mirror of https://github.com/docker/compose.git
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:
commit
5a1fea8272
|
@ -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
|
||||
|
|
|
@ -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"},
|
||||
|
|
Loading…
Reference in New Issue