Kaynağa Gözat

Merge pull request #9507 from TheodosiouTh/tc/simplify-flag-conversion

TC: Use switch case to simplify flag conversion and avoid multiple if statements
Guillaume Lours 3 yıl önce
ebeveyn
işleme
5a1fea8272

+ 6 - 5
cmd/compatibility/convert.go

@@ -58,17 +58,18 @@ func Convert(args []string) []string {
 			command = append(command, args[i:]...)
 			command = append(command, args[i:]...)
 			break
 			break
 		}
 		}
-		if arg == "--verbose" {
+
+		switch arg {
+		case "--verbose":
 			arg = "--debug"
 			arg = "--debug"
-		}
-		if arg == "-h" {
+		case "-h":
 			// docker cli has deprecated -h to avoid ambiguity with -H, while docker-compose still support it
 			// docker cli has deprecated -h to avoid ambiguity with -H, while docker-compose still support it
 			arg = "--help"
 			arg = "--help"
-		}
-		if arg == "--version" || arg == "-v" {
+		case "--version", "-v":
 			// redirect --version pseudo-command to actual command
 			// redirect --version pseudo-command to actual command
 			arg = "version"
 			arg = "version"
 		}
 		}
+
 		if contains(getBoolFlags(), arg) {
 		if contains(getBoolFlags(), arg) {
 			rootFlags = append(rootFlags, arg)
 			rootFlags = append(rootFlags, arg)
 			continue
 			continue

+ 10 - 0
cmd/compatibility/convert_test.go

@@ -43,11 +43,21 @@ func Test_convert(t *testing.T) {
 			args: []string{"--host", "tcp://1.2.3.4", "up"},
 			args: []string{"--host", "tcp://1.2.3.4", "up"},
 			want: []string{"--host", "tcp://1.2.3.4", "compose", "up"},
 			want: []string{"--host", "tcp://1.2.3.4", "compose", "up"},
 		},
 		},
+		{
+			name: "compose --verbose",
+			args: []string{"--verbose"},
+			want: []string{"--debug", "compose"},
+		},
 		{
 		{
 			name: "compose --version",
 			name: "compose --version",
 			args: []string{"--version"},
 			args: []string{"--version"},
 			want: []string{"compose", "version"},
 			want: []string{"compose", "version"},
 		},
 		},
+		{
+			name: "compose -v",
+			args: []string{"-v"},
+			want: []string{"compose", "version"},
+		},
 		{
 		{
 			name: "help",
 			name: "help",
 			args: []string{"-h"},
 			args: []string{"-h"},