Skip to content

Commit f920fd4

Browse files
committed
fix(flags)!: use --option=value for flags
This makes sure `value` can start with `-` and not mess up the parameter parsing of many programs. Signed-off-by: Leo Bergnéhr <[email protected]>
1 parent b2c740b commit f920fd4

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

pkg/exec/builder/flags.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,12 @@ func (flag Flag) ToSlice(dashes Dashes) []string {
4242
result = append(result, flagName)
4343
} else {
4444
for _, value := range flag.Values {
45-
result = append(result, flagName)
46-
result = append(result, value)
45+
if dash == dashes.Long {
46+
result = append(result, fmt.Sprintf("%s=%s", flagName, value))
47+
} else {
48+
result = append(result, flagName)
49+
result = append(result, value)
50+
}
4751
}
4852
}
4953
return result

pkg/exec/builder/flags_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func TestFlag_ToSlice(t *testing.T) {
5151
t.Run("long flag", func(t *testing.T) {
5252
f := NewFlag("full", "abc")
5353
args := f.ToSlice(testStep.GetDashes())
54-
assert.Equal(t, []string{"--full", "abc"}, args)
54+
assert.Equal(t, []string{"--full=abc"}, args)
5555
})
5656

5757
t.Run("valueless flag", func(t *testing.T) {
@@ -67,7 +67,7 @@ func TestFlag_ToSlice(t *testing.T) {
6767
t.Run("flag with non-default dashes", func(t *testing.T) {
6868
f := NewFlag("full", "abc")
6969
args := f.ToSlice(dashes)
70-
assert.Equal(t, []string{"---full", "abc"}, args)
70+
assert.Equal(t, []string{"---full=abc"}, args)
7171
})
7272
}
7373

@@ -80,7 +80,7 @@ func TestFlags_ToSlice(t *testing.T) {
8080
args := flags.ToSlice(testStep.GetDashes())
8181

8282
// Flags should be sorted and sliced up on a platter
83-
assert.Equal(t, []string{"-a", "1", "--bull", "2"}, args)
83+
assert.Equal(t, []string{"-a", "1", "--bull=2"}, args)
8484
}
8585

8686
func TestFlags_NonStringKeys(t *testing.T) {

0 commit comments

Comments
 (0)