Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ func (f *Flag) defaultIsZeroValue() bool {
case *intSliceValue, *stringSliceValue, *stringArrayValue:
return f.DefValue == "[]"
default:
switch f.Value.String() {
switch f.DefValue {
case "false":
return true
case "<nil>":
Expand Down
13 changes: 10 additions & 3 deletions flag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1183,6 +1183,7 @@ const defaultOutput = ` --A for bootstrapping, allo
--StringSlice strings string slice with zero default
--Z int an int that defaults to zero
--custom custom custom Value implementation
--custom-with-val custom custom value which has been set from command line while help is shown
--customP custom a VarP with default (default 10)
--maxT timeout set timeout for dial
-v, --verbose count verbosity
Expand Down Expand Up @@ -1234,12 +1235,18 @@ func TestPrintDefaults(t *testing.T) {
cv2 := customValue(10)
fs.VarP(&cv2, "customP", "", "a VarP with default")

// Simulate case where a value has been provided and the help screen is shown
var cv3 customValue
fs.Var(&cv3, "custom-with-val", "custom value which has been set from command line while help is shown")
err := fs.Parse([]string{"--custom-with-val", "3"})
if err != nil {
t.Error("Parsing flags failed:", err)
}

fs.PrintDefaults()
got := buf.String()
if got != defaultOutput {
fmt.Println("\n" + got)
fmt.Printf("\n" + defaultOutput)
t.Errorf("got %q want %q\n", got, defaultOutput)
t.Errorf("\n--- Got:\n%s--- Wanted:\n%s\n", got, defaultOutput)
}
}

Expand Down