@@ -64,33 +64,76 @@ func DefaultShortHelp(c *CommandInfo) string {
6464 return strings .Compare (nameToCmpA , nameToCmpB )
6565 })
6666
67- var optNameColWidth int
67+ var nonCondensedOpts bool
6868 for i := range c .Opts {
69- if l := len (c .Opts [i ].optUsgNameAndArg ()); l > optNameColWidth && l <= helpShortMsgMaxFirstColLen {
70- optNameColWidth = l
69+ if l := len (c .Opts [i ].optUsgNameAndArg ()); l >= helpShortMsgMaxFirstColLen {
70+ nonCondensedOpts = true
71+ break
7172 }
7273 }
73- for _ , o := range opts {
74- paddedNameAndArg := fmt .Sprintf (" %-*s" , optNameColWidth , o .optUsgNameAndArg ())
75- desc := o .HelpBlurb
76- if o .IsRequired {
77- desc += " (required)"
78- }
79- if o .HasStrDefault {
80- desc += fmt .Sprintf (" (default: %v)" , o .StrDefault )
74+
75+ if nonCondensedOpts {
76+ for _ , o := range opts {
77+ desc := o .HelpBlurb
78+ if o .IsRequired {
79+ desc += " (required)"
80+ }
81+ if o .HasStrDefault {
82+ desc += fmt .Sprintf (" (default: %v)" , o .StrDefault )
83+ }
84+ if o .EnvVar != "" {
85+ desc += " [$" + o .EnvVar + "]"
86+ }
87+ var namesAndVal string
88+ {
89+ if o .NameShort != "" {
90+ namesAndVal += "-" + o .NameShort
91+ }
92+ if o .NameLong != "" {
93+ if o .NameShort != "" {
94+ namesAndVal += ", "
95+ }
96+ namesAndVal += "--" + o .NameLong
97+ }
98+ if an := o .optUsgArgName (); an != "" {
99+ namesAndVal += " " + an
100+ }
101+ }
102+ content := " " + namesAndVal
103+ content += "\n " + strings .Repeat (" " , 6 )
104+ content += wrapBlurb (desc , 6 , helpMsgTextWidth )
105+ u .WriteString (content )
106+ u .WriteByte ('\n' )
81107 }
82- if o .EnvVar != "" {
83- desc += " [$" + o .EnvVar + "]"
108+ } else {
109+ var optNameColWidth int
110+ for i := range c .Opts {
111+ if l := len (c .Opts [i ].optUsgNameAndArg ()); l > optNameColWidth && l <= helpShortMsgMaxFirstColLen {
112+ optNameColWidth = l
113+ }
84114 }
85- content := paddedNameAndArg
86- if len (paddedNameAndArg ) > helpShortMsgMaxFirstColLen {
87- content += "\n " + strings .Repeat (" " , optNameColWidth + 5 )
88- } else {
89- content += " "
115+ for _ , o := range opts {
116+ paddedNameAndArg := fmt .Sprintf (" %-*s" , optNameColWidth , o .optUsgNameAndArg ())
117+ desc := o .HelpBlurb
118+ if o .IsRequired {
119+ desc += " (required)"
120+ }
121+ if o .HasStrDefault {
122+ desc += fmt .Sprintf (" (default: %v)" , o .StrDefault )
123+ }
124+ if o .EnvVar != "" {
125+ desc += " [$" + o .EnvVar + "]"
126+ }
127+ content := paddedNameAndArg
128+ if len (paddedNameAndArg ) > helpShortMsgMaxFirstColLen {
129+ content += "\n " + strings .Repeat (" " , optNameColWidth + 5 )
130+ } else {
131+ content += " "
132+ }
133+ content += wrapBlurb (desc , len (paddedNameAndArg )+ 3 , helpMsgTextWidth )
134+ u .WriteString (content )
135+ u .WriteByte ('\n' )
90136 }
91- content += wrapBlurb (desc , len (paddedNameAndArg )+ 3 , helpMsgTextWidth )
92- u .WriteString (content )
93- u .WriteByte ('\n' )
94137 }
95138
96139 if len (c .Args ) > 0 {
@@ -218,14 +261,12 @@ func DefaultFullHelp(c *CommandInfo) string {
218261 if o .NameShort != "" {
219262 usgNamesAndArg += "-" + o .NameShort
220263 }
221-
222264 if o .NameLong != "" {
223265 if o .NameShort != "" {
224266 usgNamesAndArg += ", "
225267 }
226268 usgNamesAndArg += "--" + o .NameLong
227269 }
228-
229270 if an := o .optUsgArgName (); an != "" {
230271 usgNamesAndArg += " " + an
231272 }
0 commit comments