Skip to content

Commit bc5c864

Browse files
authored
fix: CLI consistency - usage paths, trial --quiet, pr verbose, secrets examples (#18380)
1 parent 793a4fd commit bc5c864

4 files changed

Lines changed: 75 additions & 2 deletions

File tree

cmd/gh-aw/main.go

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,77 @@ func init() {
466466
// Set version template to match the version subcommand format
467467
rootCmd.SetVersionTemplate(string(constants.CLIExtensionPrefix) + " version {{.Version}}\n")
468468

469+
// Fix usage lines so subcommands show "gh aw <cmd>" instead of "gh <cmd>".
470+
// Cobra derives the root name from the first word of Use ("gh" from "gh aw"),
471+
// so CommandPath() for subcommands omits "aw". We use SetUsageFunc to
472+
// post-process the default output, replacing "gh " with "gh aw " in the
473+
// two lines that reference the command path.
474+
rootCmd.SetUsageFunc(func(cmd *cobra.Command) error {
475+
fixPath := func(s string) string {
476+
if s == "gh" {
477+
return "gh aw"
478+
}
479+
if strings.HasPrefix(s, "gh ") && !strings.HasPrefix(s, "gh aw") {
480+
return "gh aw " + s[3:]
481+
}
482+
return s
483+
}
484+
out := cmd.OutOrStderr()
485+
fmt.Fprint(out, "Usage:")
486+
if cmd.Runnable() {
487+
fmt.Fprintf(out, "\n %s", fixPath(cmd.UseLine()))
488+
}
489+
if cmd.HasAvailableSubCommands() {
490+
fmt.Fprintf(out, "\n %s [command]", fixPath(cmd.CommandPath()))
491+
}
492+
if len(cmd.Aliases) > 0 {
493+
fmt.Fprintf(out, "\n\nAliases:\n %s", cmd.NameAndAliases())
494+
}
495+
if cmd.HasExample() {
496+
fmt.Fprintf(out, "\n\nExamples:\n%s", cmd.Example)
497+
}
498+
if cmd.HasAvailableSubCommands() {
499+
cmds := cmd.Commands()
500+
if len(cmd.Groups()) == 0 {
501+
fmt.Fprint(out, "\n\nAvailable Commands:")
502+
for _, sub := range cmds {
503+
if sub.IsAvailableCommand() || sub.Name() == "help" {
504+
fmt.Fprintf(out, "\n %-11s %s", sub.Name(), sub.Short)
505+
}
506+
}
507+
} else {
508+
for _, group := range cmd.Groups() {
509+
fmt.Fprintf(out, "\n\n%s", group.Title)
510+
for _, sub := range cmds {
511+
if sub.GroupID == group.ID && (sub.IsAvailableCommand() || sub.Name() == "help") {
512+
fmt.Fprintf(out, "\n %-11s %s", sub.Name(), sub.Short)
513+
}
514+
}
515+
}
516+
if !cmd.AllChildCommandsHaveGroup() {
517+
fmt.Fprint(out, "\n\nAdditional Commands:")
518+
for _, sub := range cmds {
519+
if sub.GroupID == "" && (sub.IsAvailableCommand() || sub.Name() == "help") {
520+
fmt.Fprintf(out, "\n %-11s %s", sub.Name(), sub.Short)
521+
}
522+
}
523+
}
524+
}
525+
}
526+
if cmd.HasAvailableLocalFlags() {
527+
fmt.Fprintf(out, "\n\nFlags:\n%s", strings.TrimRight(cmd.LocalFlags().FlagUsages(), " \t\n"))
528+
}
529+
if cmd.HasAvailableInheritedFlags() {
530+
fmt.Fprintf(out, "\n\nGlobal Flags:\n%s", strings.TrimRight(cmd.InheritedFlags().FlagUsages(), " \t\n"))
531+
}
532+
if cmd.HasAvailableSubCommands() {
533+
fmt.Fprintf(out, "\n\nUse \"%s [command] --help\" for more information about a command.\n", fixPath(cmd.CommandPath()))
534+
} else {
535+
fmt.Fprintln(out)
536+
}
537+
return nil
538+
})
539+
469540
// Create custom help command that supports "all" subcommand
470541
customHelpCmd := &cobra.Command{
471542
Use: "help [command]",

pkg/cli/pr_command.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ The command will:
9898
}
9999

100100
addRepoFlag(cmd)
101-
cmd.Flags().BoolP("verbose", "v", false, "Verbose output")
102101

103102
return cmd
104103
}

pkg/cli/tokens_bootstrap.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ Only required secrets are prompted for. Optional secrets are not shown.
3434
3535
For full details, including precedence rules, see the GitHub Tokens
3636
reference in the documentation.`,
37+
Example: ` gh aw secrets bootstrap # Check and set up all required secrets
38+
gh aw secrets bootstrap --non-interactive # Display missing secrets without prompting
39+
gh aw secrets bootstrap --engine copilot # Check secrets for a specific engine`,
3740
RunE: func(cmd *cobra.Command, args []string) error {
3841
repo, _ := cmd.Flags().GetString("repo")
3942
return runTokensBootstrap(engineFlag, repo, nonInteractiveFlag)

pkg/cli/trial_command.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ Repository mode examples:
9696
Repeat and cleanup examples:
9797
` + string(constants.CLIExtensionPrefix) + ` trial githubnext/agentics/my-workflow --repeat 3 # Run 3 times total
9898
` + string(constants.CLIExtensionPrefix) + ` trial githubnext/agentics/my-workflow --delete-host-repo-after # Delete repo after completion
99-
` + string(constants.CLIExtensionPrefix) + ` trial githubnext/agentics/my-workflow --quiet --host-repo my-trial # Custom host repo
99+
` + string(constants.CLIExtensionPrefix) + ` trial githubnext/agentics/my-workflow --host-repo my-trial # Custom host repo
100100
` + string(constants.CLIExtensionPrefix) + ` trial githubnext/agentics/my-workflow --dry-run # Show what would be done without changes
101101
102102
Auto-merge examples:

0 commit comments

Comments
 (0)