Skip to content

Commit 68bd86f

Browse files
Fixed issue with default value for 'stringToString' (#50)
1 parent f55c021 commit 68bd86f

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

cobra2snooty_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ func Echo() *cobra.Command {
8080
echoCmd.PersistentFlags().BoolP("persistentbool", "p", false, "help message for flag persistentbool")
8181
echoCmd.Flags().IntP("intone", "i", 123, "help message for flag intone")
8282
echoCmd.Flags().BoolP("boolone", "b", true, "help message for flag boolone")
83+
echoCmd.Flags().StringToStringP("stringtostring", "x", nil, "help message for flag stringtostring")
8384

8485
timesCmd := &cobra.Command{
8586
Use: "times [# times] [string to echo]",
@@ -139,6 +140,9 @@ func TestGenDocs(t *testing.T) {
139140
checkStringOmits(t, output, Root().Short)
140141
checkStringContains(t, output, EchoSubCmd().Short)
141142
checkStringOmits(t, output, deprecatedCmd.Short)
143+
144+
// Verify that the text "This value defaults to" is not printed when the default value is provided to StringToStringP
145+
checkStringContains(t, output, "* - -x, --stringtostring\n - stringToString\n - false\n - help message for flag stringtostring\n *")
142146
}
143147

144148
func TestGenDocsNoHiddenParents(t *testing.T) {

flags.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func defaultIsZeroValue(f *pflag.Flag) bool {
116116
return f.DefValue == ""
117117
case "ip", "ipMask", "ipNet":
118118
return f.DefValue == nilValue
119-
case "intSlice", "stringSlice", "stringArray":
119+
case "intSlice", "stringSlice", "stringArray", "stringToString":
120120
return f.DefValue == "[]"
121121
default:
122122
switch f.Value.String() {

0 commit comments

Comments
 (0)