Merge pull request #343 from TimeIncOSS/f-hide-version
Never show version if HideVersion=true
This commit is contained in:
commit
9fec0fad02
2
app.go
2
app.go
@ -32,7 +32,7 @@ type App struct {
|
|||||||
EnableBashCompletion bool
|
EnableBashCompletion bool
|
||||||
// Boolean to hide built-in help command
|
// Boolean to hide built-in help command
|
||||||
HideHelp bool
|
HideHelp bool
|
||||||
// Boolean to hide built-in version flag
|
// Boolean to hide built-in version flag and the VERSION section of help
|
||||||
HideVersion bool
|
HideVersion bool
|
||||||
// An action to execute when the bash-completion flag is set
|
// An action to execute when the bash-completion flag is set
|
||||||
BashComplete func(context *Context)
|
BashComplete func(context *Context)
|
||||||
|
4
help.go
4
help.go
@ -16,10 +16,10 @@ var AppHelpTemplate = `NAME:
|
|||||||
|
|
||||||
USAGE:
|
USAGE:
|
||||||
{{if .UsageText}}{{.UsageText}}{{else}}{{.HelpName}} {{if .Flags}}[global options]{{end}}{{if .Commands}} command [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}}
|
{{if .UsageText}}{{.UsageText}}{{else}}{{.HelpName}} {{if .Flags}}[global options]{{end}}{{if .Commands}} command [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}}
|
||||||
{{if .Version}}
|
{{if .Version}}{{if not .HideVersion}}
|
||||||
VERSION:
|
VERSION:
|
||||||
{{.Version}}
|
{{.Version}}
|
||||||
{{end}}{{if len .Authors}}
|
{{end}}{{end}}{{if len .Authors}}
|
||||||
AUTHOR(S):
|
AUTHOR(S):
|
||||||
{{range .Authors}}{{ . }}{{end}}
|
{{range .Authors}}{{ . }}{{end}}
|
||||||
{{end}}{{if .Commands}}
|
{{end}}{{if .Commands}}
|
||||||
|
16
help_test.go
16
help_test.go
@ -35,6 +35,22 @@ func Test_ShowAppHelp_NoVersion(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Test_ShowAppHelp_HideVersion(t *testing.T) {
|
||||||
|
output := new(bytes.Buffer)
|
||||||
|
app := NewApp()
|
||||||
|
app.Writer = output
|
||||||
|
|
||||||
|
app.HideVersion = true
|
||||||
|
|
||||||
|
c := NewContext(app, nil, nil)
|
||||||
|
|
||||||
|
ShowAppHelp(c)
|
||||||
|
|
||||||
|
if bytes.Index(output.Bytes(), []byte("VERSION:")) != -1 {
|
||||||
|
t.Errorf("expected\n%snot to include %s", output.String(), "VERSION:")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func Test_Help_Custom_Flags(t *testing.T) {
|
func Test_Help_Custom_Flags(t *testing.T) {
|
||||||
oldFlag := HelpFlag
|
oldFlag := HelpFlag
|
||||||
defer func() {
|
defer func() {
|
||||||
|
Loading…
Reference in New Issue
Block a user