Skip to content

Commit

Permalink
Merge pull request #954 from urfave/inconsistent-version-behaviour-v1
Browse files Browse the repository at this point in the history
hide version if the version is not set by the user [v1]
  • Loading branch information
coilysiren committed Nov 28, 2019
2 parents 850de85 + 0e80c06 commit ebf9c3e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
5 changes: 4 additions & 1 deletion app.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ func NewApp() *App {
HelpName: filepath.Base(os.Args[0]),
Usage: "A new cli application",
UsageText: "",
Version: "0.0.0",
BashComplete: DefaultAppComplete,
Action: helpCommand.Action,
Compiled: compileTime(),
Expand Down Expand Up @@ -159,6 +158,10 @@ func (a *App) Setup() {
}
}

if a.Version == "" {
a.HideVersion = true
}

if !a.HideVersion {
a.appendFlag(VersionFlag)
}
Expand Down
5 changes: 1 addition & 4 deletions app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,7 @@ func ExampleApp_Run_noAction() {
// help, h Shows a list of commands or help for one command
//
// GLOBAL OPTIONS:
// --help, -h show help
// --version, -v print the version
// --help, -h show help
}

func ExampleApp_Run_subcommandNoAction() {
Expand Down Expand Up @@ -244,8 +243,6 @@ func ExampleApp_Run_bashComplete_withShortFlag() {
// -x
// --help
// -h
// --version
// -v
}

func ExampleApp_Run_bashComplete_withLongFlag() {
Expand Down
13 changes: 5 additions & 8 deletions docs/v1/manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,19 +150,16 @@ cli also generates neat help text:
```
$ greet help
NAME:
greet - fight the loneliness!
greet - fight the loneliness!
USAGE:
greet [global options] command [command options] [arguments...]
VERSION:
0.0.0
main [global options] command [command options] [arguments...]
COMMANDS:
help, h Shows a list of commands or help for one command
help, h Shows a list of commands or help for one command
GLOBAL OPTIONS
--version Shows version information
GLOBAL OPTIONS:
--help, -h show help
```

### Arguments
Expand Down

0 comments on commit ebf9c3e

Please sign in to comment.