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.
DefaultUsage checks
UsageFuncat the top and calls it if set:This means you can't call
DefaultUsagefrom within aUsageFuncto compose on top of it -- it recurses infinitely. The only workaround is temporarily nilling outUsageFuncbefore callingDefaultUsage:The function name already implies "give me the default behavior," so the
UsageFunccheck is surprising. Removing those lines would makeDefaultUsagecomposable without breaking any existing behavior -- commands withoutUsageFuncare unaffected, and the top-level dispatch in the library still callsUsageFuncdirectly.