mirror of
https://github.com/docker/compose.git
synced 2025-07-27 07:34:10 +02:00
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:]...)
|
command = append(command, args[i:]...)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if arg == "--verbose" {
|
|
||||||
|
switch arg {
|
||||||
|
case "--verbose":
|
||||||
arg = "--debug"
|
arg = "--debug"
|
||||||
}
|
case "-h":
|
||||||
if arg == "-h" {
|
|
||||||
// docker cli has deprecated -h to avoid ambiguity with -H, while docker-compose still support it
|
// docker cli has deprecated -h to avoid ambiguity with -H, while docker-compose still support it
|
||||||
arg = "--help"
|
arg = "--help"
|
||||||
}
|
case "--version", "-v":
|
||||||
if arg == "--version" || arg == "-v" {
|
|
||||||
// redirect --version pseudo-command to actual command
|
// redirect --version pseudo-command to actual command
|
||||||
arg = "version"
|
arg = "version"
|
||||||
}
|
}
|
||||||
|
|
||||||
if contains(getBoolFlags(), arg) {
|
if contains(getBoolFlags(), arg) {
|
||||||
rootFlags = append(rootFlags, arg)
|
rootFlags = append(rootFlags, arg)
|
||||||
continue
|
continue
|
||||||
|
@ -43,11 +43,21 @@ func Test_convert(t *testing.T) {
|
|||||||
args: []string{"--host", "tcp://1.2.3.4", "up"},
|
args: []string{"--host", "tcp://1.2.3.4", "up"},
|
||||||
want: []string{"--host", "tcp://1.2.3.4", "compose", "up"},
|
want: []string{"--host", "tcp://1.2.3.4", "compose", "up"},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "compose --verbose",
|
||||||
|
args: []string{"--verbose"},
|
||||||
|
want: []string{"--debug", "compose"},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "compose --version",
|
name: "compose --version",
|
||||||
args: []string{"--version"},
|
args: []string{"--version"},
|
||||||
want: []string{"compose", "version"},
|
want: []string{"compose", "version"},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "compose -v",
|
||||||
|
args: []string{"-v"},
|
||||||
|
want: []string{"compose", "version"},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "help",
|
name: "help",
|
||||||
args: []string{"-h"},
|
args: []string{"-h"},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user