From ff4157608f00cff62f0b080d32b674d662ac8c42 Mon Sep 17 00:00:00 2001 From: Naveen Gogineni Date: Mon, 19 May 2025 12:06:01 -0400 Subject: [PATCH 1/4] Fix:(issue_2137) Ensure default value for bool with inverse flag is honoured --- flag_bool_with_inverse.go | 1 + flag_bool_with_inverse_test.go | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/flag_bool_with_inverse.go b/flag_bool_with_inverse.go index 59ba6eea8b..c14669cf54 100644 --- a/flag_bool_with_inverse.go +++ b/flag_bool_with_inverse.go @@ -72,6 +72,7 @@ func (bif *BoolWithInverseFlag) PreParse() error { if dest == nil { dest = new(bool) } + *dest = bif.Value bif.value = &boolValue{ destination: dest, count: count, diff --git a/flag_bool_with_inverse_test.go b/flag_bool_with_inverse_test.go index 62e3007d61..dac260ae87 100644 --- a/flag_bool_with_inverse_test.go +++ b/flag_bool_with_inverse_test.go @@ -489,4 +489,23 @@ func TestBoolWithInverseDestination(t *testing.T) { t.Error(err) return } + + f := flagMethod() + f.Value = true + err = (&boolWithInverseTestCase{ + args: []string{}, + toBeSet: false, + value: true, + }).Run(t, f) + if err != nil { + t.Error(err) + return + } + + err = checkAndReset(0, true) + if err != nil { + t.Error(err) + return + } + } From 7fa2266267e3237042fb6a1d2d47537aafd99a8f Mon Sep 17 00:00:00 2001 From: Naveen Gogineni Date: Mon, 19 May 2025 16:05:06 -0400 Subject: [PATCH 2/4] Run gofumpt --- flag_bool_with_inverse_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/flag_bool_with_inverse_test.go b/flag_bool_with_inverse_test.go index dac260ae87..7113108a18 100644 --- a/flag_bool_with_inverse_test.go +++ b/flag_bool_with_inverse_test.go @@ -507,5 +507,4 @@ func TestBoolWithInverseDestination(t *testing.T) { t.Error(err) return } - } From 442955ccb15c362483b48d3b1cf22a98b8053d86 Mon Sep 17 00:00:00 2001 From: almas1992 Date: Tue, 20 May 2025 13:39:10 +0800 Subject: [PATCH 3/4] Fix:(issue_2131) Show help text for BoolWithInverseFlag --- flag_bool_with_inverse.go | 8 ++++++++ flag_bool_with_inverse_test.go | 12 ++++++++++++ help_test.go | 1 + testdata/godoc-v3.x.txt | 4 ++++ 4 files changed, 25 insertions(+) diff --git a/flag_bool_with_inverse.go b/flag_bool_with_inverse.go index c14669cf54..8d614552d4 100644 --- a/flag_bool_with_inverse.go +++ b/flag_bool_with_inverse.go @@ -151,6 +151,14 @@ func (bif *BoolWithInverseFlag) Names() []string { return names } +func (bif *BoolWithInverseFlag) IsRequired() bool { + return bif.Required +} + +func (bif *BoolWithInverseFlag) IsVisible() bool { + return !bif.Hidden +} + // String implements the standard Stringer interface. // // Example for BoolFlag{Name: "env"} diff --git a/flag_bool_with_inverse_test.go b/flag_bool_with_inverse_test.go index 7113108a18..981494586b 100644 --- a/flag_bool_with_inverse_test.go +++ b/flag_bool_with_inverse_test.go @@ -508,3 +508,15 @@ func TestBoolWithInverseDestination(t *testing.T) { return } } + +func TestBoolWithInverseFlag_SatisfiesRequiredFlagInterface(t *testing.T) { + var f RequiredFlag = &BoolWithInverseFlag{} + + _ = f.IsRequired() +} + +func TestBoolWithInverseFlag_SatisfiesVisibleFlagInterface(t *testing.T) { + var f VisibleFlag = &BoolWithInverseFlag{} + + _ = f.IsVisible() +} diff --git a/help_test.go b/help_test.go index 47ae238a50..1decf8899a 100644 --- a/help_test.go +++ b/help_test.go @@ -1726,6 +1726,7 @@ USAGE: cli.test [global options] GLOBAL OPTIONS: + --[no-]bf (default: false) --help, -h show help --m2 string --strd string diff --git a/testdata/godoc-v3.x.txt b/testdata/godoc-v3.x.txt index 93018fd5fc..ce1142b7a8 100644 --- a/testdata/godoc-v3.x.txt +++ b/testdata/godoc-v3.x.txt @@ -371,6 +371,10 @@ func (bif *BoolWithInverseFlag) IsSet() bool func (bif *BoolWithInverseFlag) Names() []string +func (bif *BoolWithInverseFlag) IsRequired() bool + +func (bif *BoolWithInverseFlag) IsVisible() bool + func (bif *BoolWithInverseFlag) PostParse() error func (bif *BoolWithInverseFlag) PreParse() error From 43d4654a5b7cb7b73c814b1e6d731d4702bd0c9f Mon Sep 17 00:00:00 2001 From: Eng Zer Jun Date: Tue, 20 May 2025 23:23:21 +0800 Subject: [PATCH 4/4] Run `make generate` and `make v3approve` Signed-off-by: Eng Zer Jun --- godoc-current.txt | 4 ++++ testdata/godoc-v3.x.txt | 10 +++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/godoc-current.txt b/godoc-current.txt index 80d4aa0c5d..44974f73ec 100644 --- a/godoc-current.txt +++ b/godoc-current.txt @@ -367,8 +367,12 @@ func (bif *BoolWithInverseFlag) IsBoolFlag() bool func (bif *BoolWithInverseFlag) IsDefaultVisible() bool IsDefaultVisible returns true if the flag is not hidden, otherwise false +func (bif *BoolWithInverseFlag) IsRequired() bool + func (bif *BoolWithInverseFlag) IsSet() bool +func (bif *BoolWithInverseFlag) IsVisible() bool + func (bif *BoolWithInverseFlag) Names() []string func (bif *BoolWithInverseFlag) PostParse() error diff --git a/testdata/godoc-v3.x.txt b/testdata/godoc-v3.x.txt index ce1142b7a8..44974f73ec 100644 --- a/testdata/godoc-v3.x.txt +++ b/testdata/godoc-v3.x.txt @@ -135,7 +135,7 @@ var SubcommandHelpTemplate = `NAME: {{template "helpNameTemplate" .}} USAGE: - {{if .UsageText}}{{wrap .UsageText 3}}{{else}}{{.FullName}}{{if .VisibleCommands}} [command [command options]] {{end}}{{if .ArgsUsage}} {{.ArgsUsage}}{{else}}{{if .Arguments}} [arguments...]{{end}}{{end}}{{end}}{{if .Category}} + {{if .UsageText}}{{wrap .UsageText 3}}{{else}}{{.FullName}}{{if .VisibleCommands}} [command [command options]]{{end}}{{if .ArgsUsage}} {{.ArgsUsage}}{{else}}{{if .Arguments}} [arguments...]{{end}}{{end}}{{end}}{{if .Category}} CATEGORY: {{.Category}}{{end}}{{if .Description}} @@ -367,14 +367,14 @@ func (bif *BoolWithInverseFlag) IsBoolFlag() bool func (bif *BoolWithInverseFlag) IsDefaultVisible() bool IsDefaultVisible returns true if the flag is not hidden, otherwise false -func (bif *BoolWithInverseFlag) IsSet() bool - -func (bif *BoolWithInverseFlag) Names() []string - func (bif *BoolWithInverseFlag) IsRequired() bool +func (bif *BoolWithInverseFlag) IsSet() bool + func (bif *BoolWithInverseFlag) IsVisible() bool +func (bif *BoolWithInverseFlag) Names() []string + func (bif *BoolWithInverseFlag) PostParse() error func (bif *BoolWithInverseFlag) PreParse() error