Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hide version if the version is not set by the user [v1] #954

Merged
merged 3 commits into from
Nov 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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