Skip to content

Commit

Permalink
cell: Fail hive configuration on duplicate flags
Browse files Browse the repository at this point in the history
When a hive declares the same configuration multiple times, only one of
them will take effect. In order to prevent resultant bugs, instead
detect and prevent such configuration in the first place.

Signed-off-by: Joe Stringer <[email protected]>
  • Loading branch information
joestringer committed Jan 18, 2025
1 parent 605c141 commit 6956598
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion cell/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,15 @@ func (c *config[Cfg]) Apply(cont container, _ rootContainer) error {

// Register the flags to the global set of all flags.
err := cont.Invoke(
func(allFlags *pflag.FlagSet) {
func(allFlags *pflag.FlagSet) error {
var err error
flags.VisitAll(func(flag *pflag.Flag) {
if allFlags.Lookup(flag.Name) != nil {
err = fmt.Errorf("Duplicate flag %s", flag.Name)
}
})
allFlags.AddFlagSet(flags)
return err
})
if err != nil {
return err
Expand Down

0 comments on commit 6956598

Please sign in to comment.