diff --git a/cmd/root.go b/cmd/root.go index 9745f72..d250741 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -248,9 +248,11 @@ func Debug(conf *cfg.Config) *cli.Command { func HelpUsage(conf *cfg.Config) *cli.Command { return &cli.Command{ - Name: "help-command-overview", - Usage: "show overview of all available commands", - Aliases: []string{"usage"}, + Name: "help-usage", + Usage: "show overview of all available commands", + UsageText: "help-usage []", + Aliases: []string{"usage"}, + CustomHelpTemplate: addReference(` implies -f`), Flags: []cli.Flag{ &cli.BoolFlag{ @@ -259,16 +261,32 @@ func HelpUsage(conf *cfg.Config) *cli.Command { Destination: &conf.Hidden, Aliases: []string{"H"}, }, + &cli.BoolFlag{ + Name: "full-commands", + Usage: "show full commands", + Destination: &conf.Force, + Aliases: []string{"f"}, + }, }, Action: func(ctx context.Context, cmd *cli.Command) error { maxCommandWidth := 0 + filter := cmd.Args().Get(0) + + if filter != "" { + conf.Force = true + } // first pass, determine max command width if err := walkVisible(conf, cmd.Root(), func(cmd *cli.Command) error { path := cmd.Path() size := len(path[len(path)-1]) + if conf.Force { + path := strings.Join(cmd.Path(), " ") + size = len(path) + } + if size > maxCommandWidth { maxCommandWidth = size } @@ -283,9 +301,19 @@ func HelpUsage(conf *cfg.Config) *cli.Command { // second pass, build tree return walkVisible(conf, cmd.Root(), func(cmd *cli.Command) error { path := cmd.Path() - command := path[len(path)-1] - if len(path) == 1 || command == "help" { + if filter != "" { + if !strings.Contains(strings.Join(path, " "), filter) { + return nil + } + } + + command := path[len(path)-1] + if conf.Force { + command = strings.Join(cmd.Path(), " ") + } + + if len(path) == 1 || strings.HasSuffix(command, "help") { return nil }