mirror of
https://github.com/docker/compose.git
synced 2025-04-08 17:05:13 +02:00
Merge pull request #11752 from ndeloof/flag_equal
fix support for `--flag=value` syntax in compatibility mode
This commit is contained in:
commit
2c9c60e007
@ -19,6 +19,7 @@ package compatibility
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/docker/compose/v2/cmd/compose"
|
"github.com/docker/compose/v2/cmd/compose"
|
||||||
)
|
)
|
||||||
@ -55,6 +56,7 @@ func Convert(args []string) []string {
|
|||||||
var rootFlags []string
|
var rootFlags []string
|
||||||
command := []string{compose.PluginName}
|
command := []string{compose.PluginName}
|
||||||
l := len(args)
|
l := len(args)
|
||||||
|
ARGS:
|
||||||
for i := 0; i < l; i++ {
|
for i := 0; i < l; i++ {
|
||||||
arg := args[i]
|
arg := args[i]
|
||||||
if contains(getCompletionCommands(), arg) {
|
if contains(getCompletionCommands(), arg) {
|
||||||
@ -81,14 +83,23 @@ func Convert(args []string) []string {
|
|||||||
rootFlags = append(rootFlags, arg)
|
rootFlags = append(rootFlags, arg)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if contains(getStringFlags(), arg) {
|
for _, flag := range getStringFlags() {
|
||||||
i++
|
if arg == flag {
|
||||||
if i >= l {
|
i++
|
||||||
fmt.Fprintf(os.Stderr, "flag needs an argument: '%s'\n", arg)
|
if i >= l {
|
||||||
os.Exit(1)
|
fmt.Fprintf(os.Stderr, "flag needs an argument: '%s'\n", arg)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
rootFlags = append(rootFlags, arg, args[i])
|
||||||
|
continue ARGS
|
||||||
|
}
|
||||||
|
if strings.HasPrefix(arg, flag) {
|
||||||
|
_, val, found := strings.Cut(arg, "=")
|
||||||
|
if found {
|
||||||
|
rootFlags = append(rootFlags, flag, val)
|
||||||
|
continue ARGS
|
||||||
|
}
|
||||||
}
|
}
|
||||||
rootFlags = append(rootFlags, arg, args[i])
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
command = append(command, arg)
|
command = append(command, arg)
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,11 @@ func Test_convert(t *testing.T) {
|
|||||||
args: []string{"--context", "foo", "-f", "compose.yaml", "up"},
|
args: []string{"--context", "foo", "-f", "compose.yaml", "up"},
|
||||||
want: []string{"--context", "foo", "compose", "-f", "compose.yaml", "up"},
|
want: []string{"--context", "foo", "compose", "-f", "compose.yaml", "up"},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "with context arg",
|
||||||
|
args: []string{"--context=foo", "-f", "compose.yaml", "up"},
|
||||||
|
want: []string{"--context", "foo", "compose", "-f", "compose.yaml", "up"},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "with host",
|
name: "with host",
|
||||||
args: []string{"--host", "tcp://1.2.3.4", "up"},
|
args: []string{"--host", "tcp://1.2.3.4", "up"},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user