mirror of
https://github.com/docker/compose.git
synced 2026-08-04 14:47:40 +00:00
Fix scan message with quiet flag
Signed-off-by: Chris Crone <christopher.crone@docker.com>
This commit is contained in:
parent
74773b9062
commit
411612ed8d
8 changed files with 77 additions and 10 deletions
|
|
@ -97,6 +97,7 @@ func runBuild(ctx context.Context, opts buildOptions, services []string) error {
|
|||
Progress: opts.progress,
|
||||
Args: types.NewMapping(opts.args),
|
||||
NoCache: opts.noCache,
|
||||
Quiet: opts.quiet,
|
||||
})
|
||||
})
|
||||
return err
|
||||
|
|
|
|||
|
|
@ -57,6 +57,17 @@ func isCommandFlag(word string) bool {
|
|||
return utils.StringContains(commandFlags, word)
|
||||
}
|
||||
|
||||
// HasQuietFlag returns true if one of the arguments is `--quiet` or `-q`
|
||||
func HasQuietFlag(args []string) bool {
|
||||
for _, a := range args {
|
||||
switch a {
|
||||
case "--quiet", "-q":
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// GetCommand get the invoked command
|
||||
func GetCommand(args []string) string {
|
||||
result := ""
|
||||
|
|
|
|||
|
|
@ -22,6 +22,36 @@ import (
|
|||
"gotest.tools/v3/assert"
|
||||
)
|
||||
|
||||
func TestHasQuietFlag(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
args []string
|
||||
expected bool
|
||||
}{
|
||||
{
|
||||
name: "long flag",
|
||||
args: []string{"build", "-t", "tag", "--quiet", "."},
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
name: "short flag",
|
||||
args: []string{"build", "-t", "tag", "-q", "."},
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
name: "no flag",
|
||||
args: []string{"build", "-t", "tag", "."},
|
||||
expected: false,
|
||||
},
|
||||
}
|
||||
for _, c := range cases {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
result := HasQuietFlag(c.args)
|
||||
assert.Equal(t, c.expected, result)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetCommand(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ func Exec(root *cobra.Command) {
|
|||
os.Exit(1)
|
||||
}
|
||||
command := metrics.GetCommand(os.Args[1:])
|
||||
if command == "build" {
|
||||
if command == "build" && !metrics.HasQuietFlag(os.Args[1:]) {
|
||||
utils.DisplayScanSuggestMsg()
|
||||
}
|
||||
metrics.Track(store.DefaultContextType, os.Args[1:], metrics.SuccessStatus)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue