1

I've got a basic config file that's mashalled and unmarshalled by viper to a struct.

type Config struct {
    field1  string
    field2  string
    field3  string
}

I want to set up cobra to let me do myapp get field1 and myapp set field1 foo for each field in my config. Ideally without hand-coding a command for each, since they all just call viper.Set and write the file.. Is it possible to get Cobra to just auto-generate the sub-commands based on the struct somehow?

XeroxDucati
  • 5,130
  • 2
  • 37
  • 66
  • Why would you make a command for each field? Just make "set" and "get" the commands and make the field name/value parameters – Adrian Sep 22 '22 at 15:18

0 Answers0