mirror of
https://codeberg.org/scip/esctl.git
synced 2026-08-24 15:14:18 +02:00
21
cmd/root.go
21
cmd/root.go
@@ -262,8 +262,25 @@ func HelpUsage(conf *cfg.Config) *cli.Command {
|
||||
},
|
||||
|
||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||
max := 22
|
||||
maxCommandWidth := 0
|
||||
|
||||
// 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 size > maxCommandWidth {
|
||||
maxCommandWidth = size
|
||||
}
|
||||
|
||||
return nil
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
maxCommandWidth += 4 // account for indent width
|
||||
|
||||
// second pass, build tree
|
||||
return walkVisible(conf, cmd.Root(), func(cmd *cli.Command) error {
|
||||
path := cmd.Path()
|
||||
command := path[len(path)-1]
|
||||
@@ -273,7 +290,7 @@ func HelpUsage(conf *cfg.Config) *cli.Command {
|
||||
}
|
||||
|
||||
indent := strings.Repeat(" ", len(path[1:])-1)
|
||||
space := strings.Repeat(" ", max-(len(command)+len(indent)))
|
||||
space := strings.Repeat(" ", maxCommandWidth-(len(command)+len(indent)))
|
||||
|
||||
fmt.Printf("%s%s %s - %s\n", indent, command, space, cmd.Usage)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user