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

Fix:(issue_1277) Remove default text for version/help flags #1633

Merged
merged 2 commits into from Jan 6, 2023
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
10 changes: 5 additions & 5 deletions app_test.go
Expand Up @@ -145,8 +145,8 @@ func ExampleApp_Run_appHelp() {
//
// GLOBAL OPTIONS:
// --name value a name to say (default: "bob")
// --help, -h show help (default: false)
// --version, -v print the version (default: false)
// --help, -h show help
// --version, -v print the version
}

func ExampleApp_Run_commandHelp() {
Expand Down Expand Up @@ -183,7 +183,7 @@ func ExampleApp_Run_commandHelp() {
// This is how we describe describeit the function
//
// OPTIONS:
// --help, -h show help (default: false)
// --help, -h show help
}

func ExampleApp_Run_noAction() {
Expand All @@ -201,7 +201,7 @@ func ExampleApp_Run_noAction() {
// help, h Shows a list of commands or help for one command
//
// GLOBAL OPTIONS:
// --help, -h show help (default: false)
// --help, -h show help
}

func ExampleApp_Run_subcommandNoAction() {
Expand All @@ -228,7 +228,7 @@ func ExampleApp_Run_subcommandNoAction() {
// This is how we describe describeit the function
//
// OPTIONS:
// --help, -h show help (default: false)
// --help, -h show help

}

Expand Down
2 changes: 2 additions & 0 deletions flag-spec.yaml
Expand Up @@ -7,6 +7,8 @@ flag_types:
- name: Count
type: int
pointer: true
- name: DisableDefaultText
type: bool
- name: Action
type: "func(*Context, bool) error"
float64:
Expand Down
23 changes: 15 additions & 8 deletions flag.go
Expand Up @@ -34,18 +34,20 @@ var BashCompletionFlag Flag = &BoolFlag{

// VersionFlag prints the version for the application
var VersionFlag Flag = &BoolFlag{
Name: "version",
Aliases: []string{"v"},
Usage: "print the version",
Name: "version",
Aliases: []string{"v"},
Usage: "print the version",
DisableDefaultText: true,
}

// HelpFlag prints the help for all commands and subcommands.
// Set to nil to disable the flag. The subcommand
// will still be added unless HideHelp or HideHelpCommand is set to true.
var HelpFlag Flag = &BoolFlag{
Name: "help",
Aliases: []string{"h"},
Usage: "show help",
Name: "help",
Aliases: []string{"h"},
Usage: "show help",
DisableDefaultText: true,
}

// FlagStringer converts a flag definition to a string. This is used by help
Expand Down Expand Up @@ -337,8 +339,13 @@ func stringifyFlag(f Flag) string {

defaultValueString := ""

if s := df.GetDefaultText(); s != "" {
defaultValueString = fmt.Sprintf(formatDefault("%s"), s)
// set default text for all flags except bool flags
// for bool flags display default text if DisableDefaultText is not
// set
if bf, ok := f.(*BoolFlag); !ok || !bf.DisableDefaultText {
if s := df.GetDefaultText(); s != "" {
defaultValueString = fmt.Sprintf(formatDefault("%s"), s)
}
}

usageWithDefault := strings.TrimSpace(usage + defaultValueString)
Expand Down
16 changes: 10 additions & 6 deletions godoc-current.txt
Expand Up @@ -455,6 +455,8 @@ type BoolFlag struct {

Count *int

DisableDefaultText bool

Action func(*Context, bool) error
// Has unexported fields.
}
Expand Down Expand Up @@ -881,18 +883,20 @@ var BashCompletionFlag Flag = &BoolFlag{
BashCompletionFlag enables bash-completion for all commands and subcommands

var HelpFlag Flag = &BoolFlag{
Name: "help",
Aliases: []string{"h"},
Usage: "show help",
Name: "help",
Aliases: []string{"h"},
Usage: "show help",
DisableDefaultText: true,
}
HelpFlag prints the help for all commands and subcommands. Set to nil to
disable the flag. The subcommand will still be added unless HideHelp or
HideHelpCommand is set to true.

var VersionFlag Flag = &BoolFlag{
Name: "version",
Aliases: []string{"v"},
Usage: "print the version",
Name: "version",
Aliases: []string{"v"},
Usage: "print the version",
DisableDefaultText: true,
}
VersionFlag prints the version for the application

Expand Down
9 changes: 3 additions & 6 deletions help_test.go
Expand Up @@ -1366,8 +1366,7 @@ DESCRIPTION:
case

OPTIONS:
--help, -h show help
(default: false)
--help, -h show help
`

if output.String() != expected {
Expand Down Expand Up @@ -1436,8 +1435,7 @@ USAGE:
even more

OPTIONS:
--help, -h show help
(default: false)
--help, -h show help
`

if output.String() != expected {
Expand Down Expand Up @@ -1514,8 +1512,7 @@ USAGE:
OPTIONS:
--test-f value my test
usage
--help, -h show help
(default: false)
--help, -h show help
`

if output.String() != expected {
Expand Down
16 changes: 10 additions & 6 deletions testdata/godoc-v2.x.txt
Expand Up @@ -455,6 +455,8 @@ type BoolFlag struct {

Count *int

DisableDefaultText bool

Action func(*Context, bool) error
// Has unexported fields.
}
Expand Down Expand Up @@ -881,18 +883,20 @@ var BashCompletionFlag Flag = &BoolFlag{
BashCompletionFlag enables bash-completion for all commands and subcommands

var HelpFlag Flag = &BoolFlag{
Name: "help",
Aliases: []string{"h"},
Usage: "show help",
Name: "help",
Aliases: []string{"h"},
Usage: "show help",
DisableDefaultText: true,
}
HelpFlag prints the help for all commands and subcommands. Set to nil to
disable the flag. The subcommand will still be added unless HideHelp or
HideHelpCommand is set to true.

var VersionFlag Flag = &BoolFlag{
Name: "version",
Aliases: []string{"v"},
Usage: "print the version",
Name: "version",
Aliases: []string{"v"},
Usage: "print the version",
DisableDefaultText: true,
}
VersionFlag prints the version for the application

Expand Down
2 changes: 2 additions & 0 deletions zz_generated.flags.go
Expand Up @@ -448,6 +448,8 @@ type BoolFlag struct {

Count *int

DisableDefaultText bool

Action func(*Context, bool) error
}

Expand Down