-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
DefaultUsage checks UsageFunc at the top and calls it if set:
func DefaultUsage(root *Command) string {
// ...
terminalCmd := root.terminal()
if terminalCmd.UsageFunc != nil {
return terminalCmd.UsageFunc(terminalCmd)
}
// ... build default output
}This means you can't call DefaultUsage from within a UsageFunc to compose on top of it -- it recurses infinitely. The only workaround is temporarily nilling out UsageFunc before calling DefaultUsage:
UsageFunc: func(c *cli.Command) string {
c.UsageFunc = nil
s := cli.DefaultUsage(c)
return s + "\n\nExamples:\n ..."
},The function name already implies "give me the default behavior," so the UsageFunc check is surprising. Removing those lines would make DefaultUsage composable without breaking any existing behavior -- commands without UsageFunc are unaffected, and the top-level dispatch in the library still calls UsageFunc directly.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels