Set attempts to read a file, then deserialize the json into a config.Config struct.
(str string)
| 44 | |
| 45 | // Set attempts to read a file, then deserialize the json into a config.Config struct. |
| 46 | func (c *SonobuoyConfig) Set(str string) error { |
| 47 | if !reflect.DeepEqual(c.Config, *config.New()) { |
| 48 | return errors.New("if a custom config file is set, it must be set before other flags that modify configuration fields") |
| 49 | } |
| 50 | |
| 51 | bytes, err := os.ReadFile(str) |
| 52 | if err != nil { |
| 53 | return errors.Wrap(err, "couldn't open config file") |
| 54 | } |
| 55 | |
| 56 | if err := json.Unmarshal(bytes, &c.Config); err != nil { |
| 57 | return errors.Wrap(err, "couldn't Unmarshal sonobuoy config") |
| 58 | } |
| 59 | |
| 60 | c.raw = string(bytes) |
| 61 | return nil |
| 62 | } |
| 63 | |
| 64 | // Get will return the config.Config. |
| 65 | func (c *SonobuoyConfig) Get() *config.Config { |