Skip to content

Commit

Permalink
Fixed issue with default value for 'stringToString' (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeroenvervaeke authored Feb 21, 2024
1 parent f55c021 commit 68bd86f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions cobra2snooty_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func Echo() *cobra.Command {
echoCmd.PersistentFlags().BoolP("persistentbool", "p", false, "help message for flag persistentbool")
echoCmd.Flags().IntP("intone", "i", 123, "help message for flag intone")
echoCmd.Flags().BoolP("boolone", "b", true, "help message for flag boolone")
echoCmd.Flags().StringToStringP("stringtostring", "x", nil, "help message for flag stringtostring")

timesCmd := &cobra.Command{
Use: "times [# times] [string to echo]",
Expand Down Expand Up @@ -139,6 +140,9 @@ func TestGenDocs(t *testing.T) {
checkStringOmits(t, output, Root().Short)
checkStringContains(t, output, EchoSubCmd().Short)
checkStringOmits(t, output, deprecatedCmd.Short)

// Verify that the text "This value defaults to" is not printed when the default value is provided to StringToStringP
checkStringContains(t, output, "* - -x, --stringtostring\n - stringToString\n - false\n - help message for flag stringtostring\n *")
}

func TestGenDocsNoHiddenParents(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func defaultIsZeroValue(f *pflag.Flag) bool {
return f.DefValue == ""
case "ip", "ipMask", "ipNet":
return f.DefValue == nilValue
case "intSlice", "stringSlice", "stringArray":
case "intSlice", "stringSlice", "stringArray", "stringToString":
return f.DefValue == "[]"
default:
switch f.Value.String() {
Expand Down

0 comments on commit 68bd86f

Please sign in to comment.