@@ -31,9 +31,9 @@ func parseFlagTag(field reflect.StructField, options opts) (*Flag, *tag.MultiTag
3131 return nil , flagTags , nil
3232 }
3333
34- flag . DefValue = flagTags .GetMany ("default" )
34+ setFlagDefaultValues ( flag , flagTags .GetMany ("default" ) )
3535 setFlagChoices (flag , flagTags .GetMany ("choice" ))
36- flag . OptionalValue = flagTags .GetMany ("optional-value" )
36+ setFlagOptionalValues ( flag , flagTags .GetMany ("optional-value" ) )
3737
3838 if options .Prefix != "" && ! ignorePrefix {
3939 flag .Name = options .Prefix + flag .Name
@@ -186,6 +186,16 @@ func parseEnvTag(flagName string, field reflect.StructField, options opts) strin
186186 return envVar
187187}
188188
189+ func setFlagDefaultValues (flag * Flag , choices []string ) {
190+ var allChoices []string
191+
192+ for _ , choice := range choices {
193+ allChoices = append (allChoices , strings .Split (choice , " " )... )
194+ }
195+
196+ flag .DefValue = allChoices
197+ }
198+
189199func setFlagChoices (flag * Flag , choices []string ) {
190200 var allChoices []string
191201
@@ -196,6 +206,16 @@ func setFlagChoices(flag *Flag, choices []string) {
196206 flag .Choices = allChoices
197207}
198208
209+ func setFlagOptionalValues (flag * Flag , choices []string ) {
210+ var allChoices []string
211+
212+ for _ , choice := range choices {
213+ allChoices = append (allChoices , strings .Split (choice , " " )... )
214+ }
215+
216+ flag .OptionalValue = allChoices
217+ }
218+
199219func hasOption (options []string , option string ) bool {
200220 for _ , opt := range options {
201221 if opt == option {
0 commit comments