Skip to content

Commit 5a1fea8

Browse files
authored
Merge pull request docker#9507 from TheodosiouTh/tc/simplify-flag-conversion
TC: Use switch case to simplify flag conversion and avoid multiple if statements
2 parents ff2bf78 + 115ac6d commit 5a1fea8

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

cmd/compatibility/convert.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,18 @@ func Convert(args []string) []string {
5858
command = append(command, args[i:]...)
5959
break
6060
}
61-
if arg == "--verbose" {
61+
62+
switch arg {
63+
case "--verbose":
6264
arg = "--debug"
63-
}
64-
if arg == "-h" {
65+
case "-h":
6566
// docker cli has deprecated -h to avoid ambiguity with -H, while docker-compose still support it
6667
arg = "--help"
67-
}
68-
if arg == "--version" || arg == "-v" {
68+
case "--version", "-v":
6969
// redirect --version pseudo-command to actual command
7070
arg = "version"
7171
}
72+
7273
if contains(getBoolFlags(), arg) {
7374
rootFlags = append(rootFlags, arg)
7475
continue

cmd/compatibility/convert_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,21 @@ func Test_convert(t *testing.T) {
4343
args: []string{"--host", "tcp://1.2.3.4", "up"},
4444
want: []string{"--host", "tcp://1.2.3.4", "compose", "up"},
4545
},
46+
{
47+
name: "compose --verbose",
48+
args: []string{"--verbose"},
49+
want: []string{"--debug", "compose"},
50+
},
4651
{
4752
name: "compose --version",
4853
args: []string{"--version"},
4954
want: []string{"compose", "version"},
5055
},
56+
{
57+
name: "compose -v",
58+
args: []string{"-v"},
59+
want: []string{"compose", "version"},
60+
},
5161
{
5262
name: "help",
5363
args: []string{"-h"},

0 commit comments

Comments
 (0)