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

TC: Use switch case to simplify flag conversion and avoid multiple if statements
This commit is contained in:
Guillaume Lours 2022-07-04 09:19:21 +02:00 committed by GitHub
commit 5a1fea8272
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 5 deletions

View File

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

View File

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