Skip to content

Commit 0d27e71

Browse files
fix: help for positional arg
1 parent 21dd700 commit 0d27e71

3 files changed

Lines changed: 26 additions & 0 deletions

File tree

internal/core/cobra_builder.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ func (b *cobraBuilder) hydrateCobra(cobraCmd *cobra.Command, cmd *Command) {
127127
if cobraCmd.HasAvailableSubCommands() || len(cobraCmd.Commands()) > 0 {
128128
cobraCmd.Annotations["CommandUsage"] += " <command>"
129129
}
130+
if positionalArg := cmd.ArgSpecs.GetPositionalArg(); positionalArg != nil {
131+
cobraCmd.Annotations["CommandUsage"] += " <" + positionalArg.Name + ">"
132+
}
130133
if cobraCmd.HasAvailableLocalFlags() || cobraCmd.HasAvailableFlags() || cobraCmd.LocalFlags() != nil {
131134
cobraCmd.Annotations["CommandUsage"] += " [flags]"
132135
}

internal/core/cobra_utils_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,13 @@ func Test_PositionalArg(t *testing.T) {
145145
Cmd: "scw test-positional plop tag=world",
146146
Check: TestCheckExitCode(0),
147147
}))
148+
149+
t.Run("full command", Test(&TestConfig{
150+
Commands: testGetCommands(),
151+
Cmd: "scw test-positional -h",
152+
Check: TestCheckCombine(
153+
TestCheckExitCode(0),
154+
TestCheckGolden(),
155+
),
156+
}))
148157
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
USAGE:
2+
scw [global-flags] test-positional <name-id> [flags] [arg=value ...]
3+
4+
ARGS:
5+
[name-id]
6+
[tag]
7+
8+
FLAGS:
9+
-h, --help help for test-positional
10+
11+
GLOBAL FLAGS:
12+
-D, --debug Enable debug mode
13+
-o, --output string Output format: json or human
14+
-p, --profile string The config profile to use

0 commit comments

Comments
 (0)