-
Notifications
You must be signed in to change notification settings - Fork 260
fix: CLI consistency - usage paths, trial --quiet, pr verbose, secrets examples #18380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -466,6 +466,77 @@ func init() { | |
| // Set version template to match the version subcommand format | ||
| rootCmd.SetVersionTemplate(string(constants.CLIExtensionPrefix) + " version {{.Version}}\n") | ||
|
|
||
| // Fix usage lines so subcommands show "gh aw <cmd>" instead of "gh <cmd>". | ||
| // Cobra derives the root name from the first word of Use ("gh" from "gh aw"), | ||
| // so CommandPath() for subcommands omits "aw". We use SetUsageFunc to | ||
| // post-process the default output, replacing "gh " with "gh aw " in the | ||
| // two lines that reference the command path. | ||
| rootCmd.SetUsageFunc(func(cmd *cobra.Command) error { | ||
| fixPath := func(s string) string { | ||
| if s == "gh" { | ||
| return "gh aw" | ||
| } | ||
| if strings.HasPrefix(s, "gh ") && !strings.HasPrefix(s, "gh aw") { | ||
| return "gh aw " + s[3:] | ||
| } | ||
| return s | ||
| } | ||
| out := cmd.OutOrStderr() | ||
| fmt.Fprint(out, "Usage:") | ||
| if cmd.Runnable() { | ||
| fmt.Fprintf(out, "\n %s", fixPath(cmd.UseLine())) | ||
| } | ||
| if cmd.HasAvailableSubCommands() { | ||
| fmt.Fprintf(out, "\n %s [command]", fixPath(cmd.CommandPath())) | ||
| } | ||
| if len(cmd.Aliases) > 0 { | ||
| fmt.Fprintf(out, "\n\nAliases:\n %s", cmd.NameAndAliases()) | ||
| } | ||
| if cmd.HasExample() { | ||
| fmt.Fprintf(out, "\n\nExamples:\n%s", cmd.Example) | ||
| } | ||
| if cmd.HasAvailableSubCommands() { | ||
| cmds := cmd.Commands() | ||
| if len(cmd.Groups()) == 0 { | ||
| fmt.Fprint(out, "\n\nAvailable Commands:") | ||
| for _, sub := range cmds { | ||
| if sub.IsAvailableCommand() || sub.Name() == "help" { | ||
| fmt.Fprintf(out, "\n %-11s %s", sub.Name(), sub.Short) | ||
| } | ||
|
Comment on lines
+500
to
+505
|
||
| } | ||
| } else { | ||
| for _, group := range cmd.Groups() { | ||
| fmt.Fprintf(out, "\n\n%s", group.Title) | ||
| for _, sub := range cmds { | ||
| if sub.GroupID == group.ID && (sub.IsAvailableCommand() || sub.Name() == "help") { | ||
| fmt.Fprintf(out, "\n %-11s %s", sub.Name(), sub.Short) | ||
| } | ||
| } | ||
| } | ||
| if !cmd.AllChildCommandsHaveGroup() { | ||
| fmt.Fprint(out, "\n\nAdditional Commands:") | ||
| for _, sub := range cmds { | ||
| if sub.GroupID == "" && (sub.IsAvailableCommand() || sub.Name() == "help") { | ||
| fmt.Fprintf(out, "\n %-11s %s", sub.Name(), sub.Short) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| if cmd.HasAvailableLocalFlags() { | ||
| fmt.Fprintf(out, "\n\nFlags:\n%s", strings.TrimRight(cmd.LocalFlags().FlagUsages(), " \t\n")) | ||
| } | ||
| if cmd.HasAvailableInheritedFlags() { | ||
| fmt.Fprintf(out, "\n\nGlobal Flags:\n%s", strings.TrimRight(cmd.InheritedFlags().FlagUsages(), " \t\n")) | ||
| } | ||
| if cmd.HasAvailableSubCommands() { | ||
| fmt.Fprintf(out, "\n\nUse \"%s [command] --help\" for more information about a command.\n", fixPath(cmd.CommandPath())) | ||
| } else { | ||
| fmt.Fprintln(out) | ||
| } | ||
| return nil | ||
| }) | ||
|
Comment on lines
+469
to
+538
|
||
|
|
||
| // Create custom help command that supports "all" subcommand | ||
| customHelpCmd := &cobra.Command{ | ||
| Use: "help [command]", | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment says this “post-process[es] the default output”, but the implementation fully re-renders the usage output (Available Commands/Flags/etc.) rather than modifying Cobra’s default output. This is misleading and also makes it easy for this usage text to drift from upstream Cobra behavior; either update the comment to match what the code does, or prefer wrapping the existing usage output and only rewriting the affected command-path substrings.