introduce --quiet option

close #1280

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
Nicolas De Loof 2021-02-16 12:10:35 +01:00
parent 220b508d53
commit c74cec9ae3
No known key found for this signature in database
GPG Key ID: 9858809D6F8F6E7E
1 changed files with 12 additions and 2 deletions

View File

@ -18,6 +18,7 @@ package compose
import (
"context"
"os"
"github.com/spf13/cobra"
@ -28,20 +29,29 @@ import (
type buildOptions struct {
*projectOptions
composeOptions
quiet bool
}
func buildCommand(p *projectOptions) *cobra.Command {
opts := buildOptions{
projectOptions: p,
}
buildCmd := &cobra.Command{
cmd := &cobra.Command{
Use: "build [SERVICE...]",
Short: "Build or rebuild services",
RunE: func(cmd *cobra.Command, args []string) error {
if opts.quiet {
devnull, err := os.Open(os.DevNull)
if err != nil {
return err
}
os.Stdout = devnull
}
return runBuild(cmd.Context(), opts, args)
},
}
return buildCmd
cmd.Flags().BoolVarP(&opts.quiet, "quiet", "q", false, "Don't print anything to STDOUT")
return cmd
}
func runBuild(ctx context.Context, opts buildOptions, services []string) error {