commit
f9982619cc
10
app.go
10
app.go
@ -108,15 +108,14 @@ func (a *App) Run(arguments []string) (err error) {
|
|||||||
fmt.Fprintln(a.Writer, nerr)
|
fmt.Fprintln(a.Writer, nerr)
|
||||||
context := NewContext(a, set, nil)
|
context := NewContext(a, set, nil)
|
||||||
ShowAppHelp(context)
|
ShowAppHelp(context)
|
||||||
fmt.Fprintln(a.Writer)
|
|
||||||
return nerr
|
return nerr
|
||||||
}
|
}
|
||||||
context := NewContext(a, set, nil)
|
context := NewContext(a, set, nil)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(a.Writer, "Incorrect Usage.\n\n")
|
fmt.Fprintln(a.Writer, "Incorrect Usage.")
|
||||||
ShowAppHelp(context)
|
|
||||||
fmt.Fprintln(a.Writer)
|
fmt.Fprintln(a.Writer)
|
||||||
|
ShowAppHelp(context)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,17 +199,18 @@ func (a *App) RunAsSubcommand(ctx *Context) (err error) {
|
|||||||
|
|
||||||
if nerr != nil {
|
if nerr != nil {
|
||||||
fmt.Fprintln(a.Writer, nerr)
|
fmt.Fprintln(a.Writer, nerr)
|
||||||
|
fmt.Fprintln(a.Writer)
|
||||||
if len(a.Commands) > 0 {
|
if len(a.Commands) > 0 {
|
||||||
ShowSubcommandHelp(context)
|
ShowSubcommandHelp(context)
|
||||||
} else {
|
} else {
|
||||||
ShowCommandHelp(ctx, context.Args().First())
|
ShowCommandHelp(ctx, context.Args().First())
|
||||||
}
|
}
|
||||||
fmt.Fprintln(a.Writer)
|
|
||||||
return nerr
|
return nerr
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(a.Writer, "Incorrect Usage.\n\n")
|
fmt.Fprintln(a.Writer, "Incorrect Usage.")
|
||||||
|
fmt.Fprintln(a.Writer)
|
||||||
ShowSubcommandHelp(context)
|
ShowSubcommandHelp(context)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -91,9 +91,9 @@ func (c Command) Run(ctx *Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprint(ctx.App.Writer, "Incorrect Usage.\n\n")
|
fmt.Fprintln(ctx.App.Writer, "Incorrect Usage.")
|
||||||
ShowCommandHelp(ctx, c.Name)
|
|
||||||
fmt.Fprintln(ctx.App.Writer)
|
fmt.Fprintln(ctx.App.Writer)
|
||||||
|
ShowCommandHelp(ctx, c.Name)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,7 +102,6 @@ func (c Command) Run(ctx *Context) error {
|
|||||||
fmt.Fprintln(ctx.App.Writer, nerr)
|
fmt.Fprintln(ctx.App.Writer, nerr)
|
||||||
fmt.Fprintln(ctx.App.Writer)
|
fmt.Fprintln(ctx.App.Writer)
|
||||||
ShowCommandHelp(ctx, c.Name)
|
ShowCommandHelp(ctx, c.Name)
|
||||||
fmt.Fprintln(ctx.App.Writer)
|
|
||||||
return nerr
|
return nerr
|
||||||
}
|
}
|
||||||
context := NewContext(ctx.App, set, ctx)
|
context := NewContext(ctx.App, set, ctx)
|
||||||
|
17
help.go
17
help.go
@ -15,22 +15,23 @@ var AppHelpTemplate = `NAME:
|
|||||||
{{.Name}} - {{.Usage}}
|
{{.Name}} - {{.Usage}}
|
||||||
|
|
||||||
USAGE:
|
USAGE:
|
||||||
{{.Name}} {{if .Flags}}[global options] {{end}}command{{if .Flags}} [command options]{{end}} [arguments...]
|
{{.Name}} {{if .Flags}}[global options]{{end}}{{if .Commands}} command [command options]{{end}} [arguments...]
|
||||||
|
{{if .Version}}
|
||||||
VERSION:
|
VERSION:
|
||||||
{{.Version}}{{if len .Authors}}
|
{{.Version}}
|
||||||
|
{{end}}{{if len .Authors}}
|
||||||
AUTHOR(S):
|
AUTHOR(S):
|
||||||
{{range .Authors}}{{ . }}{{end}}{{end}}
|
{{range .Authors}}{{ . }}{{end}}
|
||||||
|
{{end}}{{if .Commands}}
|
||||||
COMMANDS:
|
COMMANDS:
|
||||||
{{range .Commands}}{{join .Names ", "}}{{ "\t" }}{{.Usage}}
|
{{range .Commands}}{{join .Names ", "}}{{ "\t" }}{{.Usage}}
|
||||||
{{end}}{{if .Flags}}
|
{{end}}{{end}}{{if .Flags}}
|
||||||
GLOBAL OPTIONS:
|
GLOBAL OPTIONS:
|
||||||
{{range .Flags}}{{.}}
|
{{range .Flags}}{{.}}
|
||||||
{{end}}{{end}}{{if .Copyright }}
|
{{end}}{{end}}{{if .Copyright }}
|
||||||
COPYRIGHT:
|
COPYRIGHT:
|
||||||
{{.Copyright}}{{end}}
|
{{.Copyright}}
|
||||||
|
{{end}}
|
||||||
`
|
`
|
||||||
|
|
||||||
// The text template for the command help topic.
|
// The text template for the command help topic.
|
||||||
|
16
help_test.go
16
help_test.go
@ -20,3 +20,19 @@ func Test_ShowAppHelp_NoAuthor(t *testing.T) {
|
|||||||
t.Errorf("expected\n%snot to include %s", output.String(), "AUTHOR(S):")
|
t.Errorf("expected\n%snot to include %s", output.String(), "AUTHOR(S):")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Test_ShowAppHelp_NoVersion(t *testing.T) {
|
||||||
|
output := new(bytes.Buffer)
|
||||||
|
app := cli.NewApp()
|
||||||
|
app.Writer = output
|
||||||
|
|
||||||
|
app.Version = ""
|
||||||
|
|
||||||
|
c := cli.NewContext(app, nil, nil)
|
||||||
|
|
||||||
|
cli.ShowAppHelp(c)
|
||||||
|
|
||||||
|
if bytes.Index(output.Bytes(), []byte("VERSION:")) != -1 {
|
||||||
|
t.Errorf("expected\n%snot to include %s", output.String(), "VERSION:")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user