@@ -214,6 +214,13 @@ func (c *Command) UsageFunc() (f func(*Command) error) {
214
214
}
215
215
}
216
216
217
+ // Output the usage for the command
218
+ // Used when a user provides invalid input
219
+ // Can be defined by user by overriding UsageFunc
220
+ func (c * Command ) Usage () error {
221
+ return c .UsageFunc ()(c )
222
+ }
223
+
217
224
// HelpFunc returns either the function set by SetHelpFunc for this command
218
225
// or a parent, or it returns a function with default help behavior
219
226
func (c * Command ) HelpFunc () func (* Command , []string ) {
@@ -233,11 +240,19 @@ func (c *Command) HelpFunc() func(*Command, []string) {
233
240
}
234
241
}
235
242
243
+ // Output the help for the command
244
+ // Used when a user calls help [command]
245
+ // Can be defined by user by overriding HelpFunc
246
+ func (c * Command ) Help () error {
247
+ c .HelpFunc ()(c , []string {})
248
+ return nil
249
+ }
250
+
236
251
func (c * Command ) UsageString () string {
237
252
tmpOutput := c .output
238
253
bb := new (bytes.Buffer )
239
254
c .SetOutput (bb )
240
- c .UsageFunc ()( c )
255
+ c .Usage ( )
241
256
c .output = tmpOutput
242
257
return bb .String ()
243
258
}
@@ -720,9 +735,9 @@ func (c *Command) initHelpCmd() {
720
735
cmd , _ , e := c .Root ().Find (args )
721
736
if cmd == nil || e != nil {
722
737
c .Printf ("Unknown help topic %#q." , args )
723
- c .Root ().UsageFunc ()( cmd )
738
+ c .Root ().Usage ( )
724
739
} else {
725
- cmd .HelpFunc ()( cmd , args )
740
+ cmd .Help ( )
726
741
}
727
742
},
728
743
}
0 commit comments