mirror of
https://codeberg.org/scip/esctl.git
synced 2026-08-24 05:04:18 +02:00
add option -f to usage and filter support (#64)
This commit is contained in:
34
cmd/root.go
34
cmd/root.go
@@ -248,9 +248,11 @@ func Debug(conf *cfg.Config) *cli.Command {
|
|||||||
|
|
||||||
func HelpUsage(conf *cfg.Config) *cli.Command {
|
func HelpUsage(conf *cfg.Config) *cli.Command {
|
||||||
return &cli.Command{
|
return &cli.Command{
|
||||||
Name: "help-command-overview",
|
Name: "help-usage",
|
||||||
Usage: "show overview of all available commands",
|
Usage: "show overview of all available commands",
|
||||||
|
UsageText: "help-usage [<filter>]",
|
||||||
Aliases: []string{"usage"},
|
Aliases: []string{"usage"},
|
||||||
|
CustomHelpTemplate: addReference(`<filter> implies -f`),
|
||||||
|
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
&cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
@@ -259,16 +261,32 @@ func HelpUsage(conf *cfg.Config) *cli.Command {
|
|||||||
Destination: &conf.Hidden,
|
Destination: &conf.Hidden,
|
||||||
Aliases: []string{"H"},
|
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 {
|
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||||
maxCommandWidth := 0
|
maxCommandWidth := 0
|
||||||
|
filter := cmd.Args().Get(0)
|
||||||
|
|
||||||
|
if filter != "" {
|
||||||
|
conf.Force = true
|
||||||
|
}
|
||||||
|
|
||||||
// first pass, determine max command width
|
// first pass, determine max command width
|
||||||
if err := walkVisible(conf, cmd.Root(), func(cmd *cli.Command) error {
|
if err := walkVisible(conf, cmd.Root(), func(cmd *cli.Command) error {
|
||||||
path := cmd.Path()
|
path := cmd.Path()
|
||||||
size := len(path[len(path)-1])
|
size := len(path[len(path)-1])
|
||||||
|
|
||||||
|
if conf.Force {
|
||||||
|
path := strings.Join(cmd.Path(), " ")
|
||||||
|
size = len(path)
|
||||||
|
}
|
||||||
|
|
||||||
if size > maxCommandWidth {
|
if size > maxCommandWidth {
|
||||||
maxCommandWidth = size
|
maxCommandWidth = size
|
||||||
}
|
}
|
||||||
@@ -283,9 +301,19 @@ func HelpUsage(conf *cfg.Config) *cli.Command {
|
|||||||
// second pass, build tree
|
// second pass, build tree
|
||||||
return walkVisible(conf, cmd.Root(), func(cmd *cli.Command) error {
|
return walkVisible(conf, cmd.Root(), func(cmd *cli.Command) error {
|
||||||
path := cmd.Path()
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user