Skip to content

Commit c7addf1

Browse files
committed
feat(run): Add --quiet and --quiet-build options for the run command
Signed-off-by: Suleiman Dibirov <idsulik@gmail.com>
1 parent 0badcf3 commit c7addf1

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

cmd/compose/run.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ type runOptions struct {
6767
noDeps bool
6868
ignoreOrphans bool
6969
removeOrphans bool
70+
quiet bool
7071
quietPull bool
7172
}
7273

@@ -180,6 +181,14 @@ func runCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service) *
180181
options.noTty = !options.tty
181182
}
182183
}
184+
if options.quiet {
185+
progress.Mode = progress.ModeQuiet
186+
devnull, err := os.Open(os.DevNull)
187+
if err != nil {
188+
return err
189+
}
190+
os.Stdout = devnull
191+
}
183192
createOpts.pullChanged = cmd.Flags().Changed("pull")
184193
return nil
185194
}),
@@ -222,6 +231,8 @@ func runCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service) *
222231
flags.BoolVar(&options.useAliases, "use-aliases", false, "Use the service's network useAliases in the network(s) the container connects to")
223232
flags.BoolVarP(&options.servicePorts, "service-ports", "P", false, "Run command with all service's ports enabled and mapped to the host")
224233
flags.StringVar(&createOpts.Pull, "pull", "policy", `Pull image before running ("always"|"missing"|"never")`)
234+
flags.BoolVarP(&options.quiet, "quiet", "q", false, "Don't print anything to STDOUT")
235+
flags.BoolVar(&buildOpts.quiet, "quiet-build", false, "Suppress progress output from the build process")
225236
flags.BoolVar(&options.quietPull, "quiet-pull", false, "Pull without printing progress information")
226237
flags.BoolVar(&createOpts.Build, "build", false, "Build image before starting container")
227238
flags.BoolVar(&options.removeOrphans, "remove-orphans", false, "Remove containers for services not defined in the Compose file")

docs/reference/compose_run.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ specified in the service configuration.
7474
| `--no-deps` | `bool` | | Don't start linked services |
7575
| `-p`, `--publish` | `stringArray` | | Publish a container's port(s) to the host |
7676
| `--pull` | `string` | `policy` | Pull image before running ("always"\|"missing"\|"never") |
77+
| `-q`, `--quiet` | `bool` | | Don't print anything to STDOUT |
78+
| `--quiet-build` | `bool` | | Suppress progress output from the build process |
7779
| `--quiet-pull` | `bool` | | Pull without printing progress information |
7880
| `--remove-orphans` | `bool` | | Remove containers for services not defined in the Compose file |
7981
| `--rm` | `bool` | | Automatically remove the container when it exits |

docs/reference/docker_compose_run.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,27 @@ options:
200200
experimentalcli: false
201201
kubernetes: false
202202
swarm: false
203+
- option: quiet
204+
shorthand: q
205+
value_type: bool
206+
default_value: "false"
207+
description: Don't print anything to STDOUT
208+
deprecated: false
209+
hidden: false
210+
experimental: false
211+
experimentalcli: false
212+
kubernetes: false
213+
swarm: false
214+
- option: quiet-build
215+
value_type: bool
216+
default_value: "false"
217+
description: Suppress progress output from the build process
218+
deprecated: false
219+
hidden: false
220+
experimental: false
221+
experimentalcli: false
222+
kubernetes: false
223+
swarm: false
203224
- option: quiet-pull
204225
value_type: bool
205226
default_value: "false"

0 commit comments

Comments
 (0)