Skip to content

Commit

Permalink
Fix bundle run when run interactively
Browse files Browse the repository at this point in the history
The commit where resource lookup was factored out into a separate package
didn't take into account the use of `args` further down in the code.

This change fixes that oversight by returning the tail arguments when figuring
out which resource to run. The later call now no longer has to index the `args`
slice.
  • Loading branch information
pietern committed Nov 4, 2024
1 parent dd506e2 commit 1c63ee9
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions cmd/bundle/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,23 @@ func promptRunArgument(ctx context.Context, b *bundle.Bundle) (string, error) {
return key, nil
}

func resolveRunArgument(ctx context.Context, b *bundle.Bundle, args []string) (string, error) {
// resolveRunArgument resolves the resource key to run.
// It returns the remaining arguments to pass to the runner, if applicable.
func resolveRunArgument(ctx context.Context, b *bundle.Bundle, args []string) (string, []string, error) {
// If no arguments are specified, prompt the user to select something to run.
if len(args) == 0 && cmdio.IsPromptSupported(ctx) {
return promptRunArgument(ctx, b)
key, err := promptRunArgument(ctx, b)
if err != nil {
return "", nil, err
}
return key, args, nil
}

if len(args) < 1 {
return "", fmt.Errorf("expected a KEY of the resource to run")
return "", nil, fmt.Errorf("expected a KEY of the resource to run")
}

return args[0], nil
return args[0], args[1:], nil
}

func keyToRunner(b *bundle.Bundle, arg string) (run.Runner, error) {
Expand Down Expand Up @@ -109,7 +115,7 @@ task or a Python wheel task, the second example applies.
return err
}

arg, err := resolveRunArgument(ctx, b, args)
key, args, err := resolveRunArgument(ctx, b, args)
if err != nil {
return err
}
Expand All @@ -124,13 +130,13 @@ task or a Python wheel task, the second example applies.
return err
}

runner, err := keyToRunner(b, arg)
runner, err := keyToRunner(b, key)
if err != nil {
return err
}

// Parse additional positional arguments.
err = runner.ParseArgs(args[1:], &runOptions)
err = runner.ParseArgs(args, &runOptions)
if err != nil {
return err
}
Expand Down

0 comments on commit 1c63ee9

Please sign in to comment.