File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ package cli
33import (
44 "fmt"
55 "strings"
6+ "unicode/utf8"
67
78 "github.com/spf13/cobra"
89)
9495}
9596
9697func renderExperimentalCommands (commands []experimentalCommandInfo ) string {
98+ width := 0
99+ for _ , info := range commands {
100+ if w := utf8 .RuneCountInString (info .Invocation ); w > width {
101+ width = w
102+ }
103+ }
104+
97105 var out strings.Builder
98106 for _ , info := range commands {
99107 out .WriteString (" " )
100- out .WriteString (padRight (info .Invocation , 16 ))
108+ out .WriteString (padRight (info .Invocation , width ))
101109 out .WriteByte (' ' )
102110 out .WriteString (info .Summary )
103111 out .WriteByte ('\n' )
@@ -106,8 +114,9 @@ func renderExperimentalCommands(commands []experimentalCommandInfo) string {
106114}
107115
108116func padRight (value string , width int ) string {
109- if len (value ) >= width {
117+ n := utf8 .RuneCountInString (value )
118+ if n >= width {
110119 return value
111120 }
112- return value + strings .Repeat (" " , width - len ( value ) )
121+ return value + strings .Repeat (" " , width - n )
113122}
You can’t perform that action at this time.
0 commit comments