소스 검색

Collect metrics --help flag

Signed-off-by: Guillaume Tardif <[email protected]>
Guillaume Tardif 5 년 전
부모
커밋
c1fe338ac7
3개의 변경된 파일12개의 추가작업 그리고 15개의 파일을 삭제
  1. 1 1
      metrics/commands.go
  2. 1 4
      metrics/metrics.go
  3. 10 10
      metrics/metrics_test.go

+ 1 - 1
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

+ 1 - 4
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
 			}
 		}

+ 10 - 10
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:     "run with help flag",
+			args:     []string{"run", "--help"},
+			expected: "run --help",
 		},
 		{
-			name:     "help on run",
-			args:     []string{"run", "--help"},
-			expected: "",
+			name:     "with help flag before-after commands",
+			args:     []string{"compose", "--help", "up"},
+			expected: "compose --help up",
 		},
 		{
-			name:     "help on compose up",
-			args:     []string{"compose", "up", "--help"},
-			expected: "",
+			name:     "help flag",
+			args:     []string{"--help"},
+			expected: "--help",
 		},
 	}