Browse Source

TC: Use map to simplify flag conversion and avoid multilple if statements

Signed-off-by: ThedosiouTh <[email protected]>
ThedosiouTh 3 years ago
parent
commit
40f0dbd971
1 changed files with 11 additions and 10 deletions
  1. 11 10
      cmd/compatibility/convert.go

+ 11 - 10
cmd/compatibility/convert.go

@@ -43,6 +43,15 @@ func getStringFlags() []string {
 	}
 }
 
+var argToActualFlag = map[string]string{
+	"--verbose": "--debug",
+	// docker cli has deprecated -h to avoid ambiguity with -H, while docker-compose still support it
+	"-h": "--help",
+	// redirect --version pseudo-command to actual command
+	"--version": "version",
+	"-v":        "version",
+}
+
 // Convert transforms standalone docker-compose args into CLI plugin compliant ones
 func Convert(args []string) []string {
 	var rootFlags []string
@@ -58,16 +67,8 @@ func Convert(args []string) []string {
 			command = append(command, args[i:]...)
 			break
 		}
-		if arg == "--verbose" {
-			arg = "--debug"
-		}
-		if arg == "-h" {
-			// docker cli has deprecated -h to avoid ambiguity with -H, while docker-compose still support it
-			arg = "--help"
-		}
-		if arg == "--version" || arg == "-v" {
-			// redirect --version pseudo-command to actual command
-			arg = "version"
+		if actualFlag, ok := argToActualFlag[arg]; ok {
+			arg = actualFlag
 		}
 		if contains(getBoolFlags(), arg) {
 			rootFlags = append(rootFlags, arg)