Parcourir la source

Reorder `--help` flag always first in metrics

Signed-off-by: Guillaume Tardif <[email protected]>
Guillaume Tardif il y a 5 ans
Parent
commit
b238232a77
3 fichiers modifiés avec 10 ajouts et 8 suppressions
  1. 1 1
      metrics/commands.go
  2. 7 5
      metrics/metrics.go
  3. 2 2
      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", "--help",
+	"--version", "--login",
 }
 
 // Generated with generatecommands/main.go

+ 7 - 5
metrics/metrics.go

@@ -17,6 +17,8 @@
 package metrics
 
 import (
+	"strings"
+
 	"github.com/docker/compose-cli/utils"
 )
 
@@ -51,15 +53,15 @@ func GetCommand(args []string) string {
 	result := ""
 	onlyFlags := false
 	for _, arg := range args {
+		if arg == "--help" {
+			result = strings.TrimSpace(arg + " " + result)
+			continue
+		}
 		if arg == "--" {
 			break
 		}
 		if isCommandFlag(arg) || (!onlyFlags && isCommand(arg)) {
-			if result == "" {
-				result = arg
-			} else {
-				result = result + " " + arg
-			}
+			result = strings.TrimSpace(result + " " + arg)
 			if isCommand(arg) && !isManagementCommand(arg) {
 				onlyFlags = true
 			}

+ 2 - 2
metrics/metrics_test.go

@@ -162,12 +162,12 @@ func TestKeepHelpCommands(t *testing.T) {
 		{
 			name:     "run with help flag",
 			args:     []string{"run", "--help"},
-			expected: "run --help",
+			expected: "--help run",
 		},
 		{
 			name:     "with help flag before-after commands",
 			args:     []string{"compose", "--help", "up"},
-			expected: "compose --help up",
+			expected: "--help compose up",
 		},
 		{
 			name:     "help flag",