mirror of
https://codeberg.org/scip/esctl.git
synced 2026-08-24 04:54:18 +02:00
add option -f to usage and filter support (#64)
This commit is contained in:
38
cmd/root.go
38
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 [<filter>]",
|
||||
Aliases: []string{"usage"},
|
||||
CustomHelpTemplate: addReference(`<filter> 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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user