MCPcopy Index your code
hub / github.com/cortexlabs/cortex / removeEnvFromCLIConfig

Function removeEnvFromCLIConfig

cli/cmd/lib_cli_config.go:532–571  ·  view source on GitHub ↗
(envName string)

Source from the content-addressed store, hash-verified

530}
531
532func removeEnvFromCLIConfig(envName string) error {
533 cliConfig, err := readCLIConfig()
534 if err != nil {
535 return err
536 }
537
538 prevDefault, err := getDefaultEnv()
539 if err != nil {
540 return err
541 }
542
543 var updatedEnvs []*cliconfig.Environment
544 deleted := false
545 for _, env := range cliConfig.Environments {
546 if env.Name == envName {
547 deleted = true
548 continue
549 }
550 updatedEnvs = append(updatedEnvs, env)
551 }
552
553 if !deleted {
554 return cliconfig.ErrorEnvironmentNotConfigured(envName)
555 }
556
557 cliConfig.Environments = updatedEnvs
558
559 if prevDefault != nil && envName == *prevDefault {
560 cliConfig.DefaultEnvironment = nil
561 }
562 if len(cliConfig.Environments) == 1 {
563 cliConfig.DefaultEnvironment = &cliConfig.Environments[0].Name
564 }
565
566 if err := writeCLIConfig(cliConfig); err != nil {
567 return err
568 }
569
570 return nil
571}
572
573// returns the list of environment names, and whether any of them were the default
574func getEnvNamesByOperatorEndpoint(operatorEndpoint string) ([]string, bool, error) {

Callers 2

env.goFile · 0.85
cluster.goFile · 0.85

Calls 4

readCLIConfigFunction · 0.85
getDefaultEnvFunction · 0.85
writeCLIConfigFunction · 0.85

Tested by

no test coverage detected