From ee2cde7a77216d0c9eb00a39c7836ed4f5ec662f Mon Sep 17 00:00:00 2001 From: Martin Falatic Date: Wed, 24 Jun 2015 22:46:33 -0700 Subject: [PATCH 1/5] Print blank lines in help and error outputs more consistently. --- app.go | 10 +++++----- command.go | 5 ++--- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/app.go b/app.go index ac6700d..e7caec9 100644 --- a/app.go +++ b/app.go @@ -108,15 +108,14 @@ func (a *App) Run(arguments []string) (err error) { fmt.Fprintln(a.Writer, nerr) context := NewContext(a, set, nil) ShowAppHelp(context) - fmt.Fprintln(a.Writer) return nerr } context := NewContext(a, set, nil) if err != nil { - fmt.Fprintf(a.Writer, "Incorrect Usage.\n\n") - ShowAppHelp(context) + fmt.Fprintln(a.Writer, "Incorrect Usage.") fmt.Fprintln(a.Writer) + ShowAppHelp(context) return err } @@ -200,17 +199,18 @@ func (a *App) RunAsSubcommand(ctx *Context) (err error) { if nerr != nil { fmt.Fprintln(a.Writer, nerr) + fmt.Fprintln(a.Writer) if len(a.Commands) > 0 { ShowSubcommandHelp(context) } else { ShowCommandHelp(ctx, context.Args().First()) } - fmt.Fprintln(a.Writer) return nerr } if err != nil { - fmt.Fprintf(a.Writer, "Incorrect Usage.\n\n") + fmt.Fprintln(a.Writer, "Incorrect Usage.") + fmt.Fprintln(a.Writer) ShowSubcommandHelp(context) return err } diff --git a/command.go b/command.go index b721c0a..212f128 100644 --- a/command.go +++ b/command.go @@ -91,9 +91,9 @@ func (c Command) Run(ctx *Context) error { } if err != nil { - fmt.Fprint(ctx.App.Writer, "Incorrect Usage.\n\n") - ShowCommandHelp(ctx, c.Name) + fmt.Fprintln(ctx.App.Writer, "Incorrect Usage.") fmt.Fprintln(ctx.App.Writer) + ShowCommandHelp(ctx, c.Name) return err } @@ -102,7 +102,6 @@ func (c Command) Run(ctx *Context) error { fmt.Fprintln(ctx.App.Writer, nerr) fmt.Fprintln(ctx.App.Writer) ShowCommandHelp(ctx, c.Name) - fmt.Fprintln(ctx.App.Writer) return nerr } context := NewContext(ctx.App, set, ctx) From 595c055010bb8321f1a054c155ddc19ce8ae5910 Mon Sep 17 00:00:00 2001 From: Martin Falatic Date: Wed, 24 Jun 2015 23:07:32 -0700 Subject: [PATCH 2/5] If Version is an empty string, suppress version output in usage help. --- help.go | 4 ++-- help_test.go | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/help.go b/help.go index ef362f6..c80636a 100644 --- a/help.go +++ b/help.go @@ -15,10 +15,10 @@ var AppHelpTemplate = `NAME: {{.Name}} - {{.Usage}} USAGE: - {{.Name}} {{if .Flags}}[global options] {{end}}command{{if .Flags}} [command options]{{end}} [arguments...] + {{.Name}} {{if .Flags}}[global options] {{end}}command{{if .Flags}} [command options]{{end}} [arguments...]{{if len .Version}} VERSION: - {{.Version}}{{if len .Authors}} + {{.Version}}{{end}}{{if len .Authors}} AUTHOR(S): {{range .Authors}}{{ . }}{{end}}{{end}} diff --git a/help_test.go b/help_test.go index b3c1fda..bff931f 100644 --- a/help_test.go +++ b/help_test.go @@ -20,3 +20,17 @@ func Test_ShowAppHelp_NoAuthor(t *testing.T) { 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 + + 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:") + } +} From dbde3303cf0ee27c8c2ec99089b19f257d1056bf Mon Sep 17 00:00:00 2001 From: Martin Falatic Date: Wed, 24 Jun 2015 23:11:59 -0700 Subject: [PATCH 3/5] Test updated --- help_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/help_test.go b/help_test.go index bff931f..c85f957 100644 --- a/help_test.go +++ b/help_test.go @@ -26,6 +26,8 @@ func Test_ShowAppHelp_NoVersion(t *testing.T) { app := cli.NewApp() app.Writer = output + app.Version = "" + c := cli.NewContext(app, nil, nil) cli.ShowAppHelp(c) From 4d3820c145448b83214c1d951b82791cbc93a023 Mon Sep 17 00:00:00 2001 From: Martin Falatic Date: Thu, 25 Jun 2015 01:30:54 -0700 Subject: [PATCH 4/5] If there are no commands, don't show Commands section. Also fixed Copyright section formatting. --- help.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/help.go b/help.go index c80636a..7148c19 100644 --- a/help.go +++ b/help.go @@ -21,14 +21,16 @@ VERSION: {{.Version}}{{end}}{{if len .Authors}} AUTHOR(S): - {{range .Authors}}{{ . }}{{end}}{{end}} + {{range .Authors}}{{ . }}{{end}}{{end}}{{if .Commands}} COMMANDS: {{range .Commands}}{{join .Names ", "}}{{ "\t" }}{{.Usage}} - {{end}}{{if .Flags}} + {{end}}{{end}}{{if .Flags}} + GLOBAL OPTIONS: {{range .Flags}}{{.}} {{end}}{{end}}{{if .Copyright }} + COPYRIGHT: {{.Copyright}}{{end}} ` From 8cae4991af6e8b3312601375a1709e56ea7fb018 Mon Sep 17 00:00:00 2001 From: Martin Falatic Date: Thu, 25 Jun 2015 01:53:32 -0700 Subject: [PATCH 5/5] Fixing more formatting --- help.go | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/help.go b/help.go index 7148c19..e2cf82e 100644 --- a/help.go +++ b/help.go @@ -15,24 +15,23 @@ var AppHelpTemplate = `NAME: {{.Name}} - {{.Usage}} USAGE: - {{.Name}} {{if .Flags}}[global options] {{end}}command{{if .Flags}} [command options]{{end}} [arguments...]{{if len .Version}} - + {{.Name}} {{if .Flags}}[global options]{{end}}{{if .Commands}} command [command options]{{end}} [arguments...] + {{if .Version}} VERSION: - {{.Version}}{{end}}{{if len .Authors}} - + {{.Version}} + {{end}}{{if len .Authors}} AUTHOR(S): - {{range .Authors}}{{ . }}{{end}}{{end}}{{if .Commands}} - + {{range .Authors}}{{ . }}{{end}} + {{end}}{{if .Commands}} COMMANDS: {{range .Commands}}{{join .Names ", "}}{{ "\t" }}{{.Usage}} {{end}}{{end}}{{if .Flags}} - GLOBAL OPTIONS: {{range .Flags}}{{.}} {{end}}{{end}}{{if .Copyright }} - COPYRIGHT: - {{.Copyright}}{{end}} + {{.Copyright}} + {{end}} ` // The text template for the command help topic.