Skip to content

Commit fd20a9d

Browse files
committed
fix(workflow-cli): do not modify the arg of after '--'
1 parent 9c045e8 commit fd20a9d

2 files changed

Lines changed: 56 additions & 0 deletions

File tree

drycc.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,12 @@ Use 'git push drycc main' to deploy to an application.
193193
func removeConfigFlag(argv []string) []string {
194194
var kept []string
195195
for i, arg := range argv {
196+
// -- /bin/sh -c --config condition
197+
if arg == "--" {
198+
kept = append(kept, argv[i:]...)
199+
break
200+
}
201+
196202
if arg == "-c" || strings.HasPrefix(arg, "--config=") {
197203
continue
198204
// If the previous option is -c, remove the argument as well
@@ -208,6 +214,10 @@ func removeConfigFlag(argv []string) []string {
208214

209215
func getConfigFlag(argv []string) string {
210216
for i, arg := range argv {
217+
// -- /bin/sh -c/ --config= condition
218+
if arg == "--" {
219+
return ""
220+
}
211221
if strings.HasPrefix(arg, "--config=") {
212222
return strings.TrimPrefix(arg, "--config=")
213223
} else if i != 0 && argv[i-1] == "-c" {

drycc_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,24 @@ func TestGetConfigFlag(t *testing.T) {
131131
}
132132
actual = getConfigFlag(argv)
133133
assert.Equal(t, actual, expected, "config-flag")
134+
135+
expected = ""
136+
argv = []string{
137+
"--",
138+
"ipsum",
139+
"--config=config",
140+
}
141+
actual = getConfigFlag(argv)
142+
assert.Equal(t, actual, expected, "config-flag")
143+
144+
argv = []string{
145+
"--",
146+
"ipsum",
147+
"-c",
148+
"config",
149+
}
150+
actual = getConfigFlag(argv)
151+
assert.Equal(t, actual, expected, "config-flag")
134152
}
135153

136154
func TestRemoveConfigFlag(t *testing.T) {
@@ -156,4 +174,32 @@ func TestRemoveConfigFlag(t *testing.T) {
156174
}
157175
actual = removeConfigFlag(argv)
158176
assert.Equal(t, actual, expected, "args")
177+
178+
expected = []string{
179+
"--",
180+
"sh",
181+
"-c",
182+
"the-config-flag",
183+
}
184+
argv = []string{
185+
"--",
186+
"sh",
187+
"-c",
188+
"the-config-flag",
189+
}
190+
actual = removeConfigFlag(argv)
191+
assert.Equal(t, actual, expected, "args")
192+
193+
expected = []string{
194+
"--",
195+
"sh",
196+
"--config=the-config-flag",
197+
}
198+
argv = []string{
199+
"--",
200+
"sh",
201+
"--config=the-config-flag",
202+
}
203+
actual = removeConfigFlag(argv)
204+
assert.Equal(t, actual, expected, "args")
159205
}

0 commit comments

Comments
 (0)