Skip to content

Commit ebb4cde

Browse files
authored
Merge pull request #287 from lets-cli/slices-for-max-cmd-name
slices for max cmd name
2 parents cdb9386 + 25ad348 commit ebb4cde

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

cmd/root.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package cmd
22

33
import (
4+
"cmp"
45
"fmt"
6+
"slices"
57
"sort"
68
"strings"
79

@@ -61,15 +63,14 @@ func PrintHelpMessage(cmd *cobra.Command) error {
6163
}
6264

6365
func maxCommandNameLen(cmd *cobra.Command) int {
64-
maxLen := 0
65-
66-
for _, c := range cmd.Commands() {
67-
if l := len(c.Name()); l > maxLen {
68-
maxLen = l
69-
}
66+
commands := cmd.Commands()
67+
if len(commands) == 0 {
68+
return 0
7069
}
71-
72-
return maxLen
70+
maxCmd := slices.MaxFunc(commands, func(a, b *cobra.Command) int {
71+
return cmp.Compare(len(a.Name()), len(b.Name()))
72+
})
73+
return len(maxCmd.Name())
7374
}
7475

7576
func rpad(s string, padding int) string {

docs/docs/changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ title: Changelog
55

66
## [Unreleased](https://github.com/lets-cli/lets/releases/tag/v0.0.X)
77

8+
* `[Fixed]` Fixed indentation issues for long commands in help output. Command names are now properly padded for consistent alignment.
9+
810
## [0.0.58](https://github.com/lets-cli/lets/releases/tag/v0.0.58)
911

1012
* `[Added]` `group` directive for commands. Organize commands into groups for better readability in help output. See [config reference for group](/docs/config#group).

0 commit comments

Comments
 (0)