Fix spacing on subcommand names

This commit is contained in:
Evan Fiordeliso 2023-11-16 22:58:49 -05:00
parent 26bee58adc
commit b4759d5f08
2 changed files with 5 additions and 2 deletions

View File

@ -2,6 +2,7 @@ package cmd
import (
"fmt"
"strings"
"go.fifitido.net/cmd/opt"
)
@ -43,8 +44,10 @@ func (c *Command) ShowHelp() {
fmt.Println("Available subcommands:")
}
paddedWidth := c.Subcommands.MaxWidth()
for _, s := range c.Subcommands {
fmt.Println(" " + s.Name + " " + s.ShortDescription)
spaceSize := 2 + paddedWidth - len(s.Name)
fmt.Println(" " + s.Name + strings.Repeat(" ", spaceSize) + s.ShortDescription)
}
}

2
set.go
View File

@ -25,7 +25,7 @@ func (s Set) Get(name string) (*Command, bool) {
return nil, false
}
func (s Set) MaxNameWidth() int {
func (s Set) MaxWidth() int {
max := 0
for _, f := range s {
if w := len(f.Name); w > max {