Skip to content

Commit 2c9c60e

Browse files
authored
Merge pull request #11752 from ndeloof/flag_equal
fix support for `--flag=value` syntax in compatibility mode
2 parents 5682480 + 9970a84 commit 2c9c60e

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

cmd/compatibility/convert.go

+18-7
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package compatibility
1919
import (
2020
"fmt"
2121
"os"
22+
"strings"
2223

2324
"github.com/docker/compose/v2/cmd/compose"
2425
)
@@ -55,6 +56,7 @@ func Convert(args []string) []string {
5556
var rootFlags []string
5657
command := []string{compose.PluginName}
5758
l := len(args)
59+
ARGS:
5860
for i := 0; i < l; i++ {
5961
arg := args[i]
6062
if contains(getCompletionCommands(), arg) {
@@ -81,14 +83,23 @@ func Convert(args []string) []string {
8183
rootFlags = append(rootFlags, arg)
8284
continue
8385
}
84-
if contains(getStringFlags(), arg) {
85-
i++
86-
if i >= l {
87-
fmt.Fprintf(os.Stderr, "flag needs an argument: '%s'\n", arg)
88-
os.Exit(1)
86+
for _, flag := range getStringFlags() {
87+
if arg == flag {
88+
i++
89+
if i >= l {
90+
fmt.Fprintf(os.Stderr, "flag needs an argument: '%s'\n", arg)
91+
os.Exit(1)
92+
}
93+
rootFlags = append(rootFlags, arg, args[i])
94+
continue ARGS
95+
}
96+
if strings.HasPrefix(arg, flag) {
97+
_, val, found := strings.Cut(arg, "=")
98+
if found {
99+
rootFlags = append(rootFlags, flag, val)
100+
continue ARGS
101+
}
89102
}
90-
rootFlags = append(rootFlags, arg, args[i])
91-
continue
92103
}
93104
command = append(command, arg)
94105
}

cmd/compatibility/convert_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ func Test_convert(t *testing.T) {
3838
args: []string{"--context", "foo", "-f", "compose.yaml", "up"},
3939
want: []string{"--context", "foo", "compose", "-f", "compose.yaml", "up"},
4040
},
41+
{
42+
name: "with context arg",
43+
args: []string{"--context=foo", "-f", "compose.yaml", "up"},
44+
want: []string{"--context", "foo", "compose", "-f", "compose.yaml", "up"},
45+
},
4146
{
4247
name: "with host",
4348
args: []string{"--host", "tcp://1.2.3.4", "up"},

0 commit comments

Comments
 (0)