diff --git a/internal/core/cobra_builder.go b/internal/core/cobra_builder.go index 15dc13c9ed..eae3dd1aad 100644 --- a/internal/core/cobra_builder.go +++ b/internal/core/cobra_builder.go @@ -127,8 +127,8 @@ func (b *cobraBuilder) hydrateCobra(cobraCmd *cobra.Command, cmd *Command) { if cobraCmd.HasAvailableSubCommands() || len(cobraCmd.Commands()) > 0 { cobraCmd.Annotations["CommandUsage"] += " " } - 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 ...]" diff --git a/internal/core/cobra_utils_test.go b/internal/core/cobra_utils_test.go index 1c6a4d64ae..75a507e346 100644 --- a/internal/core/cobra_utils_test.go +++ b/internal/core/cobra_utils_test.go @@ -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(), + ), + })) } diff --git a/internal/core/testdata/test-positional-arg-full-command#01.stderr.golden b/internal/core/testdata/test-positional-arg-full-command#01.stderr.golden new file mode 100644 index 0000000000..5046f7e743 --- /dev/null +++ b/internal/core/testdata/test-positional-arg-full-command#01.stderr.golden @@ -0,0 +1,14 @@ +USAGE: + scw [global-flags] test-positional [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