Skip to content

Commit

Permalink
fix: checking configuration types
Browse files Browse the repository at this point in the history
  • Loading branch information
raulb committed Dec 18, 2024
1 parent 6a79dd9 commit 1afb774
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions decorators.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,14 +278,15 @@ func (CommandWithConfigDecorator) Decorate(_ *Ecdysis, cmd *cobra.Command, c Com

cfg := v.Config()

parsedType := reflect.TypeOf(cfg.Parsed)

// Ensure Parsed is a pointer
if reflect.ValueOf(cfg.Parsed).Kind() != reflect.Ptr {
if parsedType.Kind() != reflect.Ptr {
return fmt.Errorf("parsed must be a pointer")
}

// Ensure both cfg.Parsed and cfg.DefaultValues are the same type
if reflect.TypeOf(cfg.Parsed) != reflect.TypeOf(cfg.DefaultValues) {
return fmt.Errorf("parsed and DefaultValues must be the same type")
if parsedType.Elem() != reflect.TypeOf(cfg.DefaultValues) {
return fmt.Errorf("parsed and defaultValues must be the same type")
}

viper := viper.New()
Expand Down

0 comments on commit 1afb774

Please sign in to comment.