Skip to content
Myr

Make initHelpCmd public (#436)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Useful for solving #424

authored by Albert Nigmatzianov · committed by GitHub · parent ca5710c · Browse files · 1 file+24 added−23 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+24 added−23 removed

  • other:+24 added−23 removed

1 file+24 added−23 removed

modified:command.go+24 added-23 removed
698 unmodified lines
699 }700701 // initialize help as the last point possible to allow for user702 // overriding703 c.initHelpCmd()703 c.InitDefaultHelpCmd()704705 var args []string706707 // Workaround FAIL with "go test -v" or "cobra.test -test.v", see #155
55 unmodified lines
763 c.Flags().BoolP("help", "h", false, usage)764 }765}766767// InitDefaultHelpCmd adds default help command to c.768// It is called automatically by executing the c or by calling help and usage.767func (c *Command) initHelpCmd() {768 if c.helpCommand == nil {769 if !c.HasSubCommands() {770 return771 }769// If c already has help command or c has no subcommands, it will do nothing.770func (c *Command) InitDefaultHelpCmd() {771 if c.helpCommand != nil || !c.HasSubCommands() {772 return773 }774773 c.helpCommand = &Command{774 Use: "help [command]",775 Short: "Help about any command",776 Long: `Help provides help for any command in the application.775 c.helpCommand = &Command{776 Use: "help [command]",777 Short: "Help about any command",778 Long: `Help provides help for any command in the application.779 Simply type ` + c.Name() + ` help [path to command] for full details.`,778 PersistentPreRun: func(cmd *Command, args []string) {},779 PersistentPostRun: func(cmd *Command, args []string) {},780 PersistentPreRun: func(cmd *Command, args []string) {},781 PersistentPostRun: func(cmd *Command, args []string) {},782781 Run: func(c *Command, args []string) {782 cmd, _, e := c.Root().Find(args)783 if cmd == nil || e != nil {784 c.Printf("Unknown help topic %#q\n", args)785 c.Root().Usage()786 } else {787 cmd.InitDefaultHelpFlag() // make possible 'help' flag to be shown788 cmd.Help()789 }790 },791 }783 Run: func(c *Command, args []string) {784 cmd, _, e := c.Root().Find(args)785 if cmd == nil || e != nil {786 c.Printf("Unknown help topic %#q\n", args)787 c.Root().Usage()788 } else {789 cmd.InitDefaultHelpFlag() // make possible 'help' flag to be shown790 cmd.Help()791 }792 },793 }794 c.RemoveCommand(c.helpCommand)795 c.AddCommand(c.helpCommand)796}
494 unmodified lines