From c1fe338ac789df18cb920fbe07e41dcee8f810b8 Mon Sep 17 00:00:00 2001 From: Guillaume Tardif Date: Fri, 13 Nov 2020 12:44:14 +0100 Subject: [PATCH] Collect metrics --help flag Signed-off-by: Guillaume Tardif --- metrics/commands.go | 2 +- metrics/metrics.go | 5 +---- metrics/metrics_test.go | 22 +++++++++++----------- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/metrics/commands.go b/metrics/commands.go index bcf9ee91..10adbc94 100644 --- a/metrics/commands.go +++ b/metrics/commands.go @@ -18,7 +18,7 @@ package metrics var commandFlags = []string{ //added to catch scan details - "--version", "--login", + "--version", "--login", "--help", } // Generated with generatecommands/main.go diff --git a/metrics/metrics.go b/metrics/metrics.go index 3f6c3931..5b6454d4 100644 --- a/metrics/metrics.go +++ b/metrics/metrics.go @@ -51,9 +51,6 @@ func GetCommand(args []string) string { result := "" onlyFlags := false for _, arg := range args { - if arg == "--help" { - return "" - } if arg == "--" { break } @@ -63,7 +60,7 @@ func GetCommand(args []string) string { } else { result = result + " " + arg } - if !isManagementCommand(arg) { + if isCommand(arg) && !isManagementCommand(arg) { onlyFlags = true } } diff --git a/metrics/metrics_test.go b/metrics/metrics_test.go index cd66e18a..fe4e604b 100644 --- a/metrics/metrics_test.go +++ b/metrics/metrics_test.go @@ -153,26 +153,26 @@ func TestGetCommand(t *testing.T) { } } -func TestIgnoreHelpCommands(t *testing.T) { +func TestKeepHelpCommands(t *testing.T) { testCases := []struct { name string args []string expected string }{ { - name: "help", - args: []string{"--help"}, - expected: "", - }, - { - name: "help on run", + name: "run with help flag", args: []string{"run", "--help"}, - expected: "", + expected: "run --help", }, { - name: "help on compose up", - args: []string{"compose", "up", "--help"}, - expected: "", + name: "with help flag before-after commands", + args: []string{"compose", "--help", "up"}, + expected: "compose --help up", + }, + { + name: "help flag", + args: []string{"--help"}, + expected: "--help", }, }