|
|
@ -47,7 +47,7 @@ var CommandHelpTemplate = `NAME:
|
|
|
|
{{.HelpName}} - {{.Usage}}
|
|
|
|
{{.HelpName}} - {{.Usage}}
|
|
|
|
|
|
|
|
|
|
|
|
USAGE:
|
|
|
|
USAGE:
|
|
|
|
{{.HelpName}}{{if .VisibleFlags}} [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{if .Category}}
|
|
|
|
{{if .UsageText}}{{.UsageText}}{{else}}{{.HelpName}}{{if .VisibleFlags}} [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}}{{if .Category}}
|
|
|
|
|
|
|
|
|
|
|
|
CATEGORY:
|
|
|
|
CATEGORY:
|
|
|
|
{{.Category}}{{end}}{{if .Description}}
|
|
|
|
{{.Category}}{{end}}{{if .Description}}
|
|
|
@ -67,7 +67,7 @@ var SubcommandHelpTemplate = `NAME:
|
|
|
|
{{.HelpName}} - {{if .Description}}{{.Description}}{{else}}{{.Usage}}{{end}}
|
|
|
|
{{.HelpName}} - {{if .Description}}{{.Description}}{{else}}{{.Usage}}{{end}}
|
|
|
|
|
|
|
|
|
|
|
|
USAGE:
|
|
|
|
USAGE:
|
|
|
|
{{.HelpName}} command{{if .VisibleFlags}} [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}
|
|
|
|
{{if .UsageText}}{{.UsageText}}{{else}}{{.HelpName}} command{{if .VisibleFlags}} [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}}
|
|
|
|
|
|
|
|
|
|
|
|
COMMANDS:{{range .VisibleCategories}}{{if .Name}}
|
|
|
|
COMMANDS:{{range .VisibleCategories}}{{if .Name}}
|
|
|
|
{{.Name}}:{{end}}{{range .VisibleCommands}}
|
|
|
|
{{.Name}}:{{end}}{{range .VisibleCommands}}
|
|
|
@ -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) {
|
|
|
|
|
|
|
|
if c.App.CustomAppHelpTemplate == "" {
|
|
|
|
HelpPrinter(c.App.Writer, AppHelpTemplate, c.App)
|
|
|
|
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) {
|
|
|
|
|
|
|
|
if c.CustomHelpTemplate != "" {
|
|
|
|
|
|
|
|
HelpPrinterCustom(ctx.App.Writer, c.CustomHelpTemplate, c, nil)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
HelpPrinter(ctx.App.Writer, CommandHelpTemplate, c)
|
|
|
|
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,10 +250,14 @@ 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.Name != "" {
|
|
|
|
if VersionFlag.GetName() != "" {
|
|
|
|
eachName(VersionFlag.Name, func(name string) {
|
|
|
|
eachName(VersionFlag.GetName(), func(name string) {
|
|
|
|
if c.GlobalBool(name) || c.Bool(name) {
|
|
|
|
if c.GlobalBool(name) || c.Bool(name) {
|
|
|
|
found = true
|
|
|
|
found = true
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -224,8 +268,8 @@ func checkVersion(c *Context) bool {
|
|
|
|
|
|
|
|
|
|
|
|
func checkHelp(c *Context) bool {
|
|
|
|
func checkHelp(c *Context) bool {
|
|
|
|
found := false
|
|
|
|
found := false
|
|
|
|
if HelpFlag.Name != "" {
|
|
|
|
if HelpFlag.GetName() != "" {
|
|
|
|
eachName(HelpFlag.Name, func(name string) {
|
|
|
|
eachName(HelpFlag.GetName(), func(name string) {
|
|
|
|
if c.GlobalBool(name) || c.Bool(name) {
|
|
|
|
if c.GlobalBool(name) || c.Bool(name) {
|
|
|
|
found = true
|
|
|
|
found = true
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -260,7 +304,7 @@ func checkShellCompleteFlag(a *App, arguments []string) (bool, []string) {
|
|
|
|
pos := len(arguments) - 1
|
|
|
|
pos := len(arguments) - 1
|
|
|
|
lastArg := arguments[pos]
|
|
|
|
lastArg := arguments[pos]
|
|
|
|
|
|
|
|
|
|
|
|
if lastArg != "--"+BashCompletionFlag.Name {
|
|
|
|
if lastArg != "--"+BashCompletionFlag.GetName() {
|
|
|
|
return false, arguments
|
|
|
|
return false, arguments
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|