Skip to content

Commit

Permalink
flags/pflags: skip registering flags on some types
Browse files Browse the repository at this point in the history
Types that are not explicitly handled currently error out, requiring a
bunch of `dialsflag:"-"` spam. Fix this by continuing the loop when
these are encountered.
  • Loading branch information
dfinkel committed Jan 29, 2024
1 parent c805913 commit 266ab41
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions sources/flag/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,10 +315,12 @@ func (s *Set) registerFlags(tmpl reflect.Value, ptyp reflect.Type) error {
case stringSet:
s.Flags.Var(flaghelper.NewStringSetFlag(fieldVal.Addr().Interface().(*map[string]struct{})), name, help)
default:
return fmt.Errorf("unhandled type %s", ft)
// Unhandled type. Just keep going.
continue
}
default:
return fmt.Errorf("unhandled type %s", ft)
// Unhandled type. Just keep going.
continue
}
}
return nil
Expand Down
6 changes: 4 additions & 2 deletions sources/pflag/pflag.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,11 +327,13 @@ func (s *Set) registerFlags(tmpl reflect.Value, ptyp reflect.Type) error {
f = fieldVal.Addr().Interface()
s.Flags.VarP(flaghelper.NewStringSetFlag(fieldVal.Addr().Interface().(*map[string]struct{})), name, shorthand, help)
default:
return fmt.Errorf("unhandled type %s", ft)
// Unhandled type. Just keep going.
continue
}

default:
return fmt.Errorf("unhandled type %s", ft)
// Unhandled type. Just keep going.
continue
}

v := reflect.ValueOf(f)
Expand Down

0 comments on commit 266ab41

Please sign in to comment.