Skip to content

Commit

Permalink
Support appending arrays of string flags to FlagBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderguy committed Dec 7, 2024
1 parent 1770a00 commit c0e33ab
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pkg/runner/flagbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,20 @@ func (f *FlagBuilder) Append(k string, v string) {
f.AppendRaw("--"+k, v)
}

func (f *FlagBuilder) AppendArrayP(k string, array *[]string) {
if array == nil {
return
}

f.AppendArray(k, *array)
}

func (f *FlagBuilder) AppendArray(k string, array []string) {
for _, v := range array {
f.Append(k, v)
}
}

func (f *FlagBuilder) AppendInt64P(k string, v *int64) {
if v == nil {
return
Expand Down
8 changes: 8 additions & 0 deletions pkg/runner/flagbuilder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,12 @@ func TestFlagBuilderBasics(t *testing.T) {
}

assert.Equal(t, f.ToArgs(), []string{"--flag", "--another-flag", "testing", "--anumber", "42", "--pi", "3.14"})

{
n := []string{"never", "say", "die"}

f.AppendArrayP("goonies", &n)
}

assert.Equal(t, f.ToArgs(), []string{"--flag", "--another-flag", "testing", "--anumber", "42", "--pi", "3.14", "--goonies", "never", "--goonies", "say", "--goonies", "die"})
}

0 comments on commit c0e33ab

Please sign in to comment.