|
|
@ -112,17 +112,42 @@ var helpSubcommand = Command{
|
|
|
|
// Prints help for the App or Command
|
|
|
|
// Prints help for the App or Command
|
|
|
|
type helpPrinter func(w io.Writer, templ string, data interface{})
|
|
|
|
type helpPrinter func(w io.Writer, templ string, data interface{})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Prints help for the App or Command with custom template function.
|
|
|
|
|
|
|
|
type helpPrinterCustom func(w io.Writer, templ string, data interface{}, customFunc map[string]interface{})
|
|
|
|
|
|
|
|
|
|
|
|
// HelpPrinter is a function that writes the help output. If not set a default
|
|
|
|
// HelpPrinter is a function that writes the help output. If not set a default
|
|
|
|
// is used. The function signature is:
|
|
|
|
// is used. The function signature is:
|
|
|
|
// func(w io.Writer, templ string, data interface{})
|
|
|
|
// func(w io.Writer, templ string, data interface{})
|
|
|
|
var HelpPrinter helpPrinter = printHelp
|
|
|
|
var HelpPrinter helpPrinter = printHelp
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// HelpPrinterCustom is same as HelpPrinter but
|
|
|
|
|
|
|
|
// takes a custom function for template function map.
|
|
|
|
|
|
|
|
var HelpPrinterCustom helpPrinterCustom = printHelpCustom
|
|
|
|
|
|
|
|
|
|
|
|
// VersionPrinter prints the version for the App
|
|
|
|
// VersionPrinter prints the version for the App
|
|
|
|
var VersionPrinter = printVersion
|
|
|
|
var VersionPrinter = printVersion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ShowAppHelpAndExit - Prints the list of subcommands for the app and exits with exit code.
|
|
|
|
|
|
|
|
func ShowAppHelpAndExit(c *Context, exitCode int) {
|
|
|
|
|
|
|
|
ShowAppHelp(c)
|
|
|
|
|
|
|
|
os.Exit(exitCode)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ShowAppHelp is an action that displays the help.
|
|
|
|
// ShowAppHelp is an action that displays the help.
|
|
|
|
func ShowAppHelp(c *Context) error {
|
|
|
|
func ShowAppHelp(c *Context) (err error) {
|
|
|
|
HelpPrinter(c.App.Writer, AppHelpTemplate, c.App)
|
|
|
|
if c.App.CustomAppHelpTemplate == "" {
|
|
|
|
|
|
|
|
HelpPrinter(c.App.Writer, AppHelpTemplate, c.App)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
customAppData := func() map[string]interface{} {
|
|
|
|
|
|
|
|
if c.App.ExtraInfo == nil {
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return map[string]interface{}{
|
|
|
|
|
|
|
|
"ExtraInfo": c.App.ExtraInfo,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
HelpPrinterCustom(c.App.Writer, c.App.CustomAppHelpTemplate, c.App, customAppData())
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -138,6 +163,12 @@ func DefaultAppComplete(c *Context) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ShowCommandHelpAndExit - exits with code after showing help
|
|
|
|
|
|
|
|
func ShowCommandHelpAndExit(c *Context, command string, code int) {
|
|
|
|
|
|
|
|
ShowCommandHelp(c, command)
|
|
|
|
|
|
|
|
os.Exit(code)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ShowCommandHelp prints help for the given command
|
|
|
|
// ShowCommandHelp prints help for the given command
|
|
|
|
func ShowCommandHelp(ctx *Context, command string) error {
|
|
|
|
func ShowCommandHelp(ctx *Context, command string) error {
|
|
|
|
// show the subcommand help for a command with subcommands
|
|
|
|
// show the subcommand help for a command with subcommands
|
|
|
@ -148,7 +179,11 @@ func ShowCommandHelp(ctx *Context, command string) error {
|
|
|
|
|
|
|
|
|
|
|
|
for _, c := range ctx.App.Commands {
|
|
|
|
for _, c := range ctx.App.Commands {
|
|
|
|
if c.HasName(command) {
|
|
|
|
if c.HasName(command) {
|
|
|
|
HelpPrinter(ctx.App.Writer, CommandHelpTemplate, c)
|
|
|
|
if c.CustomHelpTemplate != "" {
|
|
|
|
|
|
|
|
HelpPrinterCustom(ctx.App.Writer, c.CustomHelpTemplate, c, nil)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
HelpPrinter(ctx.App.Writer, CommandHelpTemplate, c)
|
|
|
|
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -191,10 +226,15 @@ func ShowCommandCompletions(ctx *Context, command string) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func printHelp(out io.Writer, templ string, data interface{}) {
|
|
|
|
func printHelpCustom(out io.Writer, templ string, data interface{}, customFunc map[string]interface{}) {
|
|
|
|
funcMap := template.FuncMap{
|
|
|
|
funcMap := template.FuncMap{
|
|
|
|
"join": strings.Join,
|
|
|
|
"join": strings.Join,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if customFunc != nil {
|
|
|
|
|
|
|
|
for key, value := range customFunc {
|
|
|
|
|
|
|
|
funcMap[key] = value
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
w := tabwriter.NewWriter(out, 1, 8, 2, ' ', 0)
|
|
|
|
w := tabwriter.NewWriter(out, 1, 8, 2, ' ', 0)
|
|
|
|
t := template.Must(template.New("help").Funcs(funcMap).Parse(templ))
|
|
|
|
t := template.Must(template.New("help").Funcs(funcMap).Parse(templ))
|
|
|
@ -210,6 +250,10 @@ func printHelp(out io.Writer, templ string, data interface{}) {
|
|
|
|
w.Flush()
|
|
|
|
w.Flush()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func printHelp(out io.Writer, templ string, data interface{}) {
|
|
|
|
|
|
|
|
printHelpCustom(out, templ, data, nil)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func checkVersion(c *Context) bool {
|
|
|
|
func checkVersion(c *Context) bool {
|
|
|
|
found := false
|
|
|
|
found := false
|
|
|
|
if VersionFlag.GetName() != "" {
|
|
|
|
if VersionFlag.GetName() != "" {
|
|
|
|