MCPcopy
hub / github.com/urfave/cli / DefaultShowCommandHelp

Function DefaultShowCommandHelp

help.go:292–335  ·  help.go::DefaultShowCommandHelp

DefaultShowCommandHelp is the default implementation of ShowCommandHelp.

(ctx context.Context, cmd *Command, commandName string)

Source from the content-addressed store, hash-verified

290
291// DefaultShowCommandHelp is the default implementation of ShowCommandHelp.
292func DefaultShowCommandHelp(ctx context.Context, cmd *Command, commandName string) error {
293 for _, subCmd := range cmd.Commands {
294 if !subCmd.HasName(commandName) {
295 continue
296 }
297
298 tmpl := subCmd.CustomHelpTemplate
299 if tmpl == "" {
300 if len(subCmd.VisibleCommands()) == 0 {
301 tracef("using CommandHelpTemplate")
302 tmpl = CommandHelpTemplate
303 } else {
304 tracef("using SubcommandHelpTemplate")
305 tmpl = SubcommandHelpTemplate
306 }
307 }
308
309 tracef("running HelpPrinter")
310 HelpPrinter(cmd.Root().Writer, tmpl, subCmd)
311
312 tracef("returning nil after printing help")
313 return nil
314 }
315
316 tracef("no matching command found")
317
318 if cmd.CommandNotFound == nil {
319 errMsg := fmt.Sprintf("No help topic for '%v'", commandName)
320
321 if cmd.Suggest {
322 if suggestion := SuggestCommand(cmd.Commands, commandName); suggestion != "" {
323 errMsg += ". " + suggestion
324 }
325 }
326
327 tracef("exiting 3 with errMsg %[1]q", errMsg)
328 return Exit(errMsg, 3)
329 }
330
331 tracef("running CommandNotFound func for %[1]q", commandName)
332 cmd.CommandNotFound(ctx, cmd, commandName)
333
334 return nil
335}
336
337// ShowSubcommandHelpAndExit prints help for the given subcommand via ShowSubcommandHelp and exits with exit code.
338func ShowSubcommandHelpAndExit(cmd *Command, exitCode int) {

Callers

nothing calls this directly

Calls 5

tracefFunction · 0.85
ExitFunction · 0.85
RootMethod · 0.80
HasNameMethod · 0.65
VisibleCommandsMethod · 0.65

Tested by

no test coverage detected