Skip to content

Commit

Permalink
fix: help for positional arg
Browse files Browse the repository at this point in the history
  • Loading branch information
kindermoumoute committed Mar 10, 2020
1 parent 21dd700 commit fef196c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions internal/core/cobra_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ func (b *cobraBuilder) hydrateCobra(cobraCmd *cobra.Command, cmd *Command) {
if cobraCmd.HasAvailableSubCommands() || len(cobraCmd.Commands()) > 0 {
cobraCmd.Annotations["CommandUsage"] += " <command>"
}
if cobraCmd.HasAvailableLocalFlags() || cobraCmd.HasAvailableFlags() || cobraCmd.LocalFlags() != nil {
cobraCmd.Annotations["CommandUsage"] += " [flags]"
if positionalArg := cmd.ArgSpecs.GetPositionalArg(); positionalArg != nil {
cobraCmd.Annotations["CommandUsage"] += " <" + positionalArg.Name + ">"
}
if len(cmd.ArgSpecs) > 0 {
cobraCmd.Annotations["CommandUsage"] += " [arg=value ...]"
Expand Down
9 changes: 9 additions & 0 deletions internal/core/cobra_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,13 @@ func Test_PositionalArg(t *testing.T) {
Cmd: "scw test-positional plop tag=world",
Check: TestCheckExitCode(0),
}))

t.Run("full command", Test(&TestConfig{
Commands: testGetCommands(),
Cmd: "scw test-positional -h",
Check: TestCheckCombine(
TestCheckExitCode(0),
TestCheckGolden(),
),
}))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
USAGE:
scw [global-flags] test-positional <name-id> [arg=value ...]

ARGS:
[name-id]
[tag]

FLAGS:
-h, --help help for test-positional

GLOBAL FLAGS:
-D, --debug Enable debug mode
-o, --output string Output format: json or human
-p, --profile string The config profile to use

0 comments on commit fef196c

Please sign in to comment.