Skip to content

Commit

Permalink
fix: CLI args marked as greedy were not greedy (#975)
Browse files Browse the repository at this point in the history
## Description:
Fixes #974 

## Is this change user facing?
NO
<!-- If yes, please add the "user facing" label to the PR -->
<!-- If yes, don't forget to include docs changes where relevant -->

## References (if applicable):
<!-- Add relevant Github Issues, Discord threads, or other helpful
information. -->
  • Loading branch information
Guillaume Bouvignies committed Jul 26, 2023
1 parent f1b53a2 commit e6ff482
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion cli/cli/command_framework/lowlevel/lowlevel_kurtosis_command.go
Expand Up @@ -151,6 +151,8 @@ func (kurtosisCmd *LowlevelKurtosisCommand) MustGetCobraCommand() *cobra.Command
// - Any arg after an optional arg (the parser wouldn't know whether you want the optional arg or the one after it)
// - Any arg after an arg that consumes N args (since the CLI couldn't know where the greedy arg stops and the required arg begins)
terminalArgKey := ""
numberOfRequiredArgs := 0
lastArgIsGreedy := false
for _, argConfig := range kurtosisCmd.Args {
key := argConfig.Key
if terminalArgKey != "" {
Expand All @@ -161,8 +163,12 @@ func (kurtosisCmd *LowlevelKurtosisCommand) MustGetCobraCommand() *cobra.Command
key,
))
}
if !argConfig.IsOptional {
numberOfRequiredArgs += 1
}
if argConfig.IsOptional || argConfig.IsGreedy {
terminalArgKey = key
lastArgIsGreedy = argConfig.IsGreedy
}
}

Expand Down Expand Up @@ -319,7 +325,11 @@ func (kurtosisCmd *LowlevelKurtosisCommand) MustGetCobraCommand() *cobra.Command
Long: kurtosisCmd.LongDescription,
ValidArgsFunction: getCompletionsFunc,
RunE: cobraRunFunc,
Args: cobra.MaximumNArgs(len(kurtosisCmd.Args)),
}
if lastArgIsGreedy {
result.Args = cobra.MinimumNArgs(numberOfRequiredArgs)
} else {
result.Args = cobra.RangeArgs(numberOfRequiredArgs, len(kurtosisCmd.Args))
}

// Validates that the default values for the declared flags match the declard types, and add them to the Cobra command
Expand Down

0 comments on commit e6ff482

Please sign in to comment.