@@ -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 \n Aliases:\n %s" , cmd .NameAndAliases ())
494+ }
495+ if cmd .HasExample () {
496+ fmt .Fprintf (out , "\n \n Examples:\n %s" , cmd .Example )
497+ }
498+ if cmd .HasAvailableSubCommands () {
499+ cmds := cmd .Commands ()
500+ if len (cmd .Groups ()) == 0 {
501+ fmt .Fprint (out , "\n \n Available 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 \n Additional 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 \n Flags:\n %s" , strings .TrimRight (cmd .LocalFlags ().FlagUsages (), " \t \n " ))
528+ }
529+ if cmd .HasAvailableInheritedFlags () {
530+ fmt .Fprintf (out , "\n \n Global Flags:\n %s" , strings .TrimRight (cmd .InheritedFlags ().FlagUsages (), " \t \n " ))
531+ }
532+ if cmd .HasAvailableSubCommands () {
533+ fmt .Fprintf (out , "\n \n Use \" %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]" ,
0 commit comments