Skip to content

Commit eb55549

Browse files
committed
feat(run): Add --quiet and --quiet-build options for the run command
Signed-off-by: Suleiman Dibirov <[email protected]>
1 parent 0badcf3 commit eb55549

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

cmd/compose/run.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"github.com/compose-spec/compose-go/v2/types"
3232
"github.com/docker/cli/cli/command"
3333
"github.com/docker/cli/opts"
34+
ui "github.com/docker/compose/v2/pkg/progress"
3435
"github.com/mattn/go-shellwords"
3536
"github.com/spf13/cobra"
3637
"github.com/spf13/pflag"
@@ -67,6 +68,8 @@ type runOptions struct {
6768
noDeps bool
6869
ignoreOrphans bool
6970
removeOrphans bool
71+
quiet bool
72+
quietBuild bool
7073
quietPull bool
7174
}
7275

@@ -180,6 +183,14 @@ func runCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service) *
180183
options.noTty = !options.tty
181184
}
182185
}
186+
if options.quiet {
187+
ui.Mode = ui.ModeQuiet
188+
devnull, err := os.Open(os.DevNull)
189+
if err != nil {
190+
return err
191+
}
192+
os.Stdout = devnull
193+
}
183194
createOpts.pullChanged = cmd.Flags().Changed("pull")
184195
return nil
185196
}),
@@ -222,6 +233,8 @@ func runCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service) *
222233
flags.BoolVar(&options.useAliases, "use-aliases", false, "Use the service's network useAliases in the network(s) the container connects to")
223234
flags.BoolVarP(&options.servicePorts, "service-ports", "P", false, "Run command with all service's ports enabled and mapped to the host")
224235
flags.StringVar(&createOpts.Pull, "pull", "policy", `Pull image before running ("always"|"missing"|"never")`)
236+
flags.BoolVarP(&options.quiet, "quiet", "q", false, "Don't print anything to STDOUT")
237+
flags.BoolVar(&buildOpts.quiet, "quiet-build", false, "Suppress progress output from the build process")
225238
flags.BoolVar(&options.quietPull, "quiet-pull", false, "Pull without printing progress information")
226239
flags.BoolVar(&createOpts.Build, "build", false, "Build image before starting container")
227240
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)