Skip to content

Commit 8ea26ce

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

2 files changed

Lines changed: 62 additions & 0 deletions

File tree

drycc.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,19 @@ Use 'git push drycc main' to deploy to an application.
192192

193193
func removeConfigFlag(argv []string) []string {
194194
var kept []string
195+
var dashIndex int = -1
195196
for i, arg := range argv {
197+
// -- /bin/sh -c --config condition
198+
if arg == "--" {
199+
kept = append(kept, arg)
200+
dashIndex = i
201+
continue
202+
}
203+
if dashIndex != -1 && dashIndex < i {
204+
kept = append(kept, arg)
205+
continue
206+
}
207+
196208
if arg == "-c" || strings.HasPrefix(arg, "--config=") {
197209
continue
198210
// If the previous option is -c, remove the argument as well
@@ -208,6 +220,10 @@ func removeConfigFlag(argv []string) []string {
208220

209221
func getConfigFlag(argv []string) string {
210222
for i, arg := range argv {
223+
// -- /bin/sh -c/ --config= condition
224+
if arg == "--" {
225+
return ""
226+
}
211227
if strings.HasPrefix(arg, "--config=") {
212228
return strings.TrimPrefix(arg, "--config=")
213229
} 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)