(newEnv cliconfig.Environment, setAsDefault bool)
| 500 | } |
| 501 | |
| 502 | func addEnvToCLIConfig(newEnv cliconfig.Environment, setAsDefault bool) error { |
| 503 | cliConfig, err := readCLIConfig() |
| 504 | if err != nil { |
| 505 | return errors.Wrap(err, "unable to configure cli environment") |
| 506 | } |
| 507 | |
| 508 | replaced := false |
| 509 | for i, prevEnv := range cliConfig.Environments { |
| 510 | if prevEnv.Name == newEnv.Name { |
| 511 | cliConfig.Environments[i] = &newEnv |
| 512 | replaced = true |
| 513 | break |
| 514 | } |
| 515 | } |
| 516 | |
| 517 | if !replaced { |
| 518 | cliConfig.Environments = append(cliConfig.Environments, &newEnv) |
| 519 | } |
| 520 | |
| 521 | if setAsDefault { |
| 522 | cliConfig.DefaultEnvironment = &newEnv.Name |
| 523 | } |
| 524 | |
| 525 | if err := writeCLIConfig(cliConfig); err != nil { |
| 526 | return errors.Wrap(err, "unable to configure cli environment") |
| 527 | } |
| 528 | |
| 529 | return nil |
| 530 | } |
| 531 | |
| 532 | func removeEnvFromCLIConfig(envName string) error { |
| 533 | cliConfig, err := readCLIConfig() |
no test coverage detected