|
|
@ -3,6 +3,7 @@ package cli
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"io"
|
|
|
|
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
"strings"
|
|
|
|
"text/tabwriter"
|
|
|
|
"text/tabwriter"
|
|
|
|
"text/template"
|
|
|
|
"text/template"
|
|
|
@ -22,9 +23,9 @@ VERSION:
|
|
|
|
{{end}}{{end}}{{if len .Authors}}
|
|
|
|
{{end}}{{end}}{{if len .Authors}}
|
|
|
|
AUTHOR(S):
|
|
|
|
AUTHOR(S):
|
|
|
|
{{range .Authors}}{{.}}{{end}}
|
|
|
|
{{range .Authors}}{{.}}{{end}}
|
|
|
|
{{end}}{{if .Commands}}
|
|
|
|
{{end}}{{if .VisibleCommands}}
|
|
|
|
COMMANDS:{{range .Categories}}{{if .Name}}
|
|
|
|
COMMANDS:{{range .VisibleCategories}}{{if .Name}}
|
|
|
|
{{.Name}}{{ ":" }}{{end}}{{range .Commands}}
|
|
|
|
{{.Name}}:{{end}}{{range .VisibleCommands}}
|
|
|
|
{{.Name}}{{with .ShortName}}, {{.}}{{end}}{{"\t"}}{{.Usage}}{{end}}
|
|
|
|
{{.Name}}{{with .ShortName}}, {{.}}{{end}}{{"\t"}}{{.Usage}}{{end}}
|
|
|
|
{{end}}{{end}}{{if .VisibleFlags}}
|
|
|
|
{{end}}{{end}}{{if .VisibleFlags}}
|
|
|
|
GLOBAL OPTIONS:
|
|
|
|
GLOBAL OPTIONS:
|
|
|
@ -64,8 +65,8 @@ var SubcommandHelpTemplate = `NAME:
|
|
|
|
USAGE:
|
|
|
|
USAGE:
|
|
|
|
{{.HelpName}} command{{if .VisibleFlags}} [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}
|
|
|
|
{{.HelpName}} command{{if .VisibleFlags}} [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}
|
|
|
|
|
|
|
|
|
|
|
|
COMMANDS:{{range .Categories}}{{if .Name}}
|
|
|
|
COMMANDS:{{range .VisibleCategories}}{{if .Name}}
|
|
|
|
{{.Name}}{{ ":" }}{{end}}{{range .Commands}}
|
|
|
|
{{.Name}}:{{end}}{{range .VisibleCommands}}
|
|
|
|
{{.Name}}{{with .ShortName}}, {{.}}{{end}}{{"\t"}}{{.Usage}}{{end}}
|
|
|
|
{{.Name}}{{with .ShortName}}, {{.}}{{end}}{{"\t"}}{{.Usage}}{{end}}
|
|
|
|
{{end}}{{if .VisibleFlags}}
|
|
|
|
{{end}}{{if .VisibleFlags}}
|
|
|
|
OPTIONS:
|
|
|
|
OPTIONS:
|
|
|
@ -81,10 +82,10 @@ var helpCommand = Command{
|
|
|
|
Action: func(c *Context) error {
|
|
|
|
Action: func(c *Context) error {
|
|
|
|
args := c.Args()
|
|
|
|
args := c.Args()
|
|
|
|
if args.Present() {
|
|
|
|
if args.Present() {
|
|
|
|
ShowCommandHelp(c, args.First())
|
|
|
|
return ShowCommandHelp(c, args.First())
|
|
|
|
} else {
|
|
|
|
|
|
|
|
ShowAppHelp(c)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ShowAppHelp(c)
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -97,11 +98,10 @@ var helpSubcommand = Command{
|
|
|
|
Action: func(c *Context) error {
|
|
|
|
Action: func(c *Context) error {
|
|
|
|
args := c.Args()
|
|
|
|
args := c.Args()
|
|
|
|
if args.Present() {
|
|
|
|
if args.Present() {
|
|
|
|
ShowCommandHelp(c, args.First())
|
|
|
|
return ShowCommandHelp(c, args.First())
|
|
|
|
} else {
|
|
|
|
|
|
|
|
ShowSubcommandHelp(c)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
|
|
|
|
|
|
|
|
return ShowSubcommandHelp(c)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -120,6 +120,9 @@ func ShowAppHelp(c *Context) {
|
|
|
|
// Prints the list of subcommands as the default app completion method
|
|
|
|
// Prints the list of subcommands as the default app completion method
|
|
|
|
func DefaultAppComplete(c *Context) {
|
|
|
|
func DefaultAppComplete(c *Context) {
|
|
|
|
for _, command := range c.App.Commands {
|
|
|
|
for _, command := range c.App.Commands {
|
|
|
|
|
|
|
|
if command.Hidden {
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
}
|
|
|
|
for _, name := range command.Names() {
|
|
|
|
for _, name := range command.Names() {
|
|
|
|
fmt.Fprintln(c.App.Writer, name)
|
|
|
|
fmt.Fprintln(c.App.Writer, name)
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -127,30 +130,31 @@ func DefaultAppComplete(c *Context) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Prints help for the given command
|
|
|
|
// Prints help for the given command
|
|
|
|
func ShowCommandHelp(ctx *Context, command string) {
|
|
|
|
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
|
|
|
|
if command == "" {
|
|
|
|
if command == "" {
|
|
|
|
HelpPrinter(ctx.App.Writer, SubcommandHelpTemplate, ctx.App)
|
|
|
|
HelpPrinter(ctx.App.Writer, SubcommandHelpTemplate, ctx.App)
|
|
|
|
return
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
HelpPrinter(ctx.App.Writer, CommandHelpTemplate, c)
|
|
|
|
return
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ctx.App.CommandNotFound != nil {
|
|
|
|
if ctx.App.CommandNotFound == nil {
|
|
|
|
ctx.App.CommandNotFound(ctx, command)
|
|
|
|
return NewExitError(fmt.Sprintf("No help topic for '%v'", command), 3)
|
|
|
|
} else {
|
|
|
|
|
|
|
|
fmt.Fprintf(ctx.App.Writer, "No help topic for '%v'\n", command)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ctx.App.CommandNotFound(ctx, command)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Prints help for the given subcommand
|
|
|
|
// Prints help for the given subcommand
|
|
|
|
func ShowSubcommandHelp(c *Context) {
|
|
|
|
func ShowSubcommandHelp(c *Context) error {
|
|
|
|
ShowCommandHelp(c, c.Command.Name)
|
|
|
|
return ShowCommandHelp(c, c.Command.Name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Prints the version number of the App
|
|
|
|
// Prints the version number of the App
|
|
|
@ -188,7 +192,10 @@ func printHelp(out io.Writer, templ string, data interface{}) {
|
|
|
|
err := t.Execute(w, data)
|
|
|
|
err := t.Execute(w, data)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
// If the writer is closed, t.Execute will fail, and there's nothing
|
|
|
|
// If the writer is closed, t.Execute will fail, and there's nothing
|
|
|
|
// we can do to recover. We could send this to os.Stderr if we need.
|
|
|
|
// we can do to recover.
|
|
|
|
|
|
|
|
if os.Getenv("CLI_TEMPLATE_ERROR_DEBUG") != "" {
|
|
|
|
|
|
|
|
fmt.Fprintf(ErrWriter, "CLI TEMPLATE ERROR: %#v\n", err)
|
|
|
|
|
|
|
|
}
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
w.Flush()
|
|
|
|
w.Flush()
|
|
|
|