diff --git a/.palantir/go-version b/.palantir/go-version index beddcb5d..83534e24 100644 --- a/.palantir/go-version +++ b/.palantir/go-version @@ -1 +1 @@ -go1.19.4 \ No newline at end of file +go1.20 \ No newline at end of file diff --git a/generated_src/internal/amalgomated_flag/example_test.go b/generated_src/internal/amalgomated_flag/example_test.go index 04a0d20e..088447d4 100644 --- a/generated_src/internal/amalgomated_flag/example_test.go +++ b/generated_src/internal/amalgomated_flag/example_test.go @@ -78,6 +78,8 @@ func Example() { // to enable the flag package to see the flags defined there, one must // execute, typically at the start of main (not init!): // flag.Parse() - // We don't run it here because this is not a main function and - // the testing suite has already parsed the flags. + // We don't call it here because this code is a function called "Example" + // that is part of the testing suite for the package, which has already + // parsed the flags. When viewed at pkg.go.dev, however, the function is + // renamed to "main" and it could be run as a standalone example. } diff --git a/generated_src/internal/amalgomated_flag/flag.go b/generated_src/internal/amalgomated_flag/flag.go index 9abf8d76..ef3cf29c 100644 --- a/generated_src/internal/amalgomated_flag/flag.go +++ b/generated_src/internal/amalgomated_flag/flag.go @@ -550,9 +550,11 @@ func UnquoteUsage(flag *Flag) (name string, usage string) { } // No explicit name, so use type if we can find one. name = "value" - switch flag.Value.(type) { + switch fv := flag.Value.(type) { case boolFlag: - name = "" + if fv.IsBoolFlag() { + name = "" + } case *durationValue: name = "duration" case *float64Value: @@ -1054,9 +1056,9 @@ func (f *FlagSet) parseOne() (bool, error) { break } } - m := f.formal - flag, alreadythere := m[name] // BUG - if !alreadythere { + + flag, ok := f.formal[name] + if !ok { if name == "help" || name == "h" { // special case for nice help message. f.usage() return false, ErrHelp diff --git a/generated_src/internal/amalgomated_flag/flag_test.go b/generated_src/internal/amalgomated_flag/flag_test.go index ca6ba5d1..17551684 100644 --- a/generated_src/internal/amalgomated_flag/flag_test.go +++ b/generated_src/internal/amalgomated_flag/flag_test.go @@ -356,10 +356,35 @@ func TestUserDefinedBool(t *testing.T) { } } -func TestSetOutput(t *testing.T) { +func TestUserDefinedBoolUsage(t *testing.T) { var flags FlagSet + flags.Init("test", ContinueOnError) var buf bytes.Buffer flags.SetOutput(&buf) + var b boolFlagVar + flags.Var(&b, "b", "X") + b.count = 0 + // b.IsBoolFlag() will return true and usage will look boolean. + flags.PrintDefaults() + got := buf.String() + want := " -b\tX\n" + if got != want { + t.Errorf("false: want %q; got %q", want, got) + } + b.count = 4 + // b.IsBoolFlag() will return false and usage will look non-boolean. + flags.PrintDefaults() + got = buf.String() + want = " -b\tX\n -b value\n \tX\n" + if got != want { + t.Errorf("false: want %q; got %q", want, got) + } +} + +func TestSetOutput(t *testing.T) { + var flags FlagSet + var buf strings.Builder + flags.SetOutput(&buf) flags.Init("test", ContinueOnError) flags.Parse([]string{"-unknown"}) if out := buf.String(); !strings.Contains(out, "-unknown") { @@ -488,7 +513,7 @@ panic calling String method on zero flag_test.zeroPanicker for flag ZP1: panic! func TestPrintDefaults(t *testing.T) { fs := NewFlagSet("print defaults test", ContinueOnError) - var buf bytes.Buffer + var buf strings.Builder fs.SetOutput(&buf) fs.Bool("A", false, "for bootstrapping, allow 'any' type") fs.Bool("Alongflagname", false, "disable bounds checking") @@ -531,7 +556,7 @@ func TestIntFlagOverflow(t *testing.T) { // Issue 20998: Usage should respect CommandLine.output. func TestUsageOutput(t *testing.T) { ResetForTesting(DefaultUsage) - var buf bytes.Buffer + var buf strings.Builder CommandLine.SetOutput(&buf) defer func(old []string) { os.Args = old }(os.Args) os.Args = []string{"app", "-i=1", "-unknown"} @@ -726,7 +751,7 @@ func TestInvalidFlags(t *testing.T) { testName := fmt.Sprintf("FlagSet.Var(&v, %q, \"\")", test.flag) fs := NewFlagSet("", ContinueOnError) - buf := bytes.NewBuffer(nil) + buf := &strings.Builder{} fs.SetOutput(buf) mustPanic(t, testName, test.errorMsg, func() { @@ -758,7 +783,7 @@ func TestRedefinedFlags(t *testing.T) { testName := fmt.Sprintf("flag redefined in FlagSet(%q)", test.flagSetName) fs := NewFlagSet(test.flagSetName, ContinueOnError) - buf := bytes.NewBuffer(nil) + buf := &strings.Builder{} fs.SetOutput(buf) var v flagVar diff --git a/go.mod b/go.mod index d00a2f8c..d76abf81 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/palantir/godel-okgo-asset-ineffassign -go 1.19 +go 1.20 require ( github.com/gordonklaus/ineffassign v0.0.0-20210914165742-4cc7213b9bc8