Skip to content

Commit 40f0dbd

Browse files
committed
TC: Use map to simplify flag conversion and avoid multilple if statements
Signed-off-by: ThedosiouTh <[email protected]>
1 parent 5b6b674 commit 40f0dbd

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

cmd/compatibility/convert.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ func getStringFlags() []string {
4343
}
4444
}
4545

46+
var argToActualFlag = map[string]string{
47+
"--verbose": "--debug",
48+
// docker cli has deprecated -h to avoid ambiguity with -H, while docker-compose still support it
49+
"-h": "--help",
50+
// redirect --version pseudo-command to actual command
51+
"--version": "version",
52+
"-v": "version",
53+
}
54+
4655
// Convert transforms standalone docker-compose args into CLI plugin compliant ones
4756
func Convert(args []string) []string {
4857
var rootFlags []string
@@ -58,16 +67,8 @@ func Convert(args []string) []string {
5867
command = append(command, args[i:]...)
5968
break
6069
}
61-
if arg == "--verbose" {
62-
arg = "--debug"
63-
}
64-
if arg == "-h" {
65-
// docker cli has deprecated -h to avoid ambiguity with -H, while docker-compose still support it
66-
arg = "--help"
67-
}
68-
if arg == "--version" || arg == "-v" {
69-
// redirect --version pseudo-command to actual command
70-
arg = "version"
70+
if actualFlag, ok := argToActualFlag[arg]; ok {
71+
arg = actualFlag
7172
}
7273
if contains(getBoolFlags(), arg) {
7374
rootFlags = append(rootFlags, arg)

0 commit comments

Comments
 (0)