Skip to content

Commit

Permalink
context: use varargs
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Jan 21, 2023
1 parent 75bb174 commit 0664a57
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion context.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ type Context struct {
mockedReplies map[string]string
}

func NewContext(args []string) Context {
func NewContext(args ...string) Context {
if len(args) == 0 {
args = append(args, "")
}

context := Context{
CallbackValue: args[len(args)-1],
Args: args[:len(args)-1],
Expand Down
2 changes: 1 addition & 1 deletion pkg/sandbox/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func Run(t *testing.T, pkg string) (f func(func(s *Sandbox))) {

// Run executes the sandbox with given arguments.
func (s *Sandbox) Run(args ...string) run {
c := carapace.NewContext(args)
c := carapace.NewContext(args...)
for key, value := range s.env {
c.Setenv(key, value)
}
Expand Down
2 changes: 1 addition & 1 deletion traverse.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func traverse(c *cobra.Command, args []string) (Action, Context) {
var inFlag *InFlag // last encountered flag that still expects arguments
fs := pflagfork.FlagSet{FlagSet: c.Flags()}

context := NewContext(args)
context := NewContext(args...)
loop:
for i, arg := range context.Args {
switch {
Expand Down

0 comments on commit 0664a57

Please sign in to comment.