mirror of
https://github.com/docker/compose.git
synced 2025-07-23 05:34:36 +02:00
Do not send metrics for help commands
Signed-off-by: Guillaume Tardif <guillaume.tardif@docker.com>
This commit is contained in:
parent
3e93a690d2
commit
a09983b474
@ -19,7 +19,7 @@ package metrics
|
|||||||
var commandFlags = []string{
|
var commandFlags = []string{
|
||||||
//added to catch scan details
|
//added to catch scan details
|
||||||
"--version", "--login",
|
"--version", "--login",
|
||||||
"--help", "-h"}
|
}
|
||||||
|
|
||||||
// Generated with generatecommands/main.go
|
// Generated with generatecommands/main.go
|
||||||
var managementCommands = []string{
|
var managementCommands = []string{
|
||||||
|
@ -51,6 +51,9 @@ func GetCommand(args []string) string {
|
|||||||
result := ""
|
result := ""
|
||||||
onlyFlags := false
|
onlyFlags := false
|
||||||
for _, arg := range args {
|
for _, arg := range args {
|
||||||
|
if arg == "--help" {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
if arg == "--" {
|
if arg == "--" {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -58,6 +58,11 @@ func TestGetCommand(t *testing.T) {
|
|||||||
args: []string{"image", "ls"},
|
args: []string{"image", "ls"},
|
||||||
expected: "image ls",
|
expected: "image ls",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "management command with flag",
|
||||||
|
args: []string{"image", "--test", "ls"},
|
||||||
|
expected: "image ls",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "management subcommand with flag",
|
name: "management subcommand with flag",
|
||||||
args: []string{"image", "ls", "-q"},
|
args: []string{"image", "ls", "-q"},
|
||||||
@ -148,7 +153,7 @@ func TestGetCommand(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFlags(t *testing.T) {
|
func TestIgnoreHelpCommands(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
name string
|
name string
|
||||||
args []string
|
args []string
|
||||||
@ -157,22 +162,17 @@ func TestFlags(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "help",
|
name: "help",
|
||||||
args: []string{"--help"},
|
args: []string{"--help"},
|
||||||
expected: "--help",
|
expected: "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "help on run",
|
name: "help on run",
|
||||||
args: []string{"run", "--help"},
|
args: []string{"run", "--help"},
|
||||||
expected: "run --help",
|
expected: "",
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "-h on run",
|
|
||||||
args: []string{"run", "-h"},
|
|
||||||
expected: "run -h",
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "help on compose up",
|
name: "help on compose up",
|
||||||
args: []string{"compose", "up", "--help"},
|
args: []string{"compose", "up", "--help"},
|
||||||
expected: "compose up --help",
|
expected: "",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,6 +164,17 @@ func TestContextMetrics(t *testing.T) {
|
|||||||
s.Start()
|
s.Start()
|
||||||
defer s.Stop()
|
defer s.Stop()
|
||||||
|
|
||||||
|
t.Run("do not send metrics on help commands", func(t *testing.T) {
|
||||||
|
s.ResetUsage()
|
||||||
|
|
||||||
|
c.RunDockerCmd("--help")
|
||||||
|
c.RunDockerCmd("ps", "--help")
|
||||||
|
c.RunDockerCmd("run", "--help")
|
||||||
|
|
||||||
|
usage := s.GetUsage()
|
||||||
|
assert.Equal(t, 0, len(usage))
|
||||||
|
})
|
||||||
|
|
||||||
t.Run("metrics on default context", func(t *testing.T) {
|
t.Run("metrics on default context", func(t *testing.T) {
|
||||||
s.ResetUsage()
|
s.ResetUsage()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user