diff --git a/cmd/root.go b/cmd/root.go index 7fa55de..97f9062 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -1,7 +1,9 @@ package cmd import ( + "cmp" "fmt" + "slices" "sort" "strings" @@ -61,15 +63,14 @@ func PrintHelpMessage(cmd *cobra.Command) error { } func maxCommandNameLen(cmd *cobra.Command) int { - maxLen := 0 - - for _, c := range cmd.Commands() { - if l := len(c.Name()); l > maxLen { - maxLen = l - } + commands := cmd.Commands() + if len(commands) == 0 { + return 0 } - - return maxLen + maxCmd := slices.MaxFunc(commands, func(a, b *cobra.Command) int { + return cmp.Compare(len(a.Name()), len(b.Name())) + }) + return len(maxCmd.Name()) } func rpad(s string, padding int) string { diff --git a/docs/docs/changelog.md b/docs/docs/changelog.md index 4b2b163..46e81b8 100644 --- a/docs/docs/changelog.md +++ b/docs/docs/changelog.md @@ -5,6 +5,8 @@ title: Changelog ## [Unreleased](https://github.com/lets-cli/lets/releases/tag/v0.0.X) +* `[Fixed]` Fixed indentation issues for long commands in help output. Command names are now properly padded for consistent alignment. + ## [0.0.58](https://github.com/lets-cli/lets/releases/tag/v0.0.58) * `[Added]` `group` directive for commands. Organize commands into groups for better readability in help output. See [config reference for group](/docs/config#group).