SetDefaultProject sets the default project for the selected account in accounts.yaml file if empty value provided it will try to project from server & prompts user to select project from server response
(project string)
| 57 | // SetDefaultProject sets the default project for the selected account in accounts.yaml file |
| 58 | // if empty value provided it will try to project from server & prompts user to select project from server response |
| 59 | func SetDefaultProject(project string) error { |
| 60 | // we are disabling logs because getting projects from sc may print unnecessary logs |
| 61 | logrus.SetOutput(ioutil.Discard) |
| 62 | objs, _ := GetProjectsFromSC() |
| 63 | logrus.SetOutput(os.Stdout) |
| 64 | |
| 65 | if project == "" { |
| 66 | if len(objs) > 0 { |
| 67 | projects := make([]string, 0) |
| 68 | for _, obj := range objs { |
| 69 | projects = append(projects, obj.ID) |
| 70 | } |
| 71 | if err := input.Survey.AskOne(&survey.Select{Message: "Select default project for this account", Options: projects}, &project); err != nil { |
| 72 | return err |
| 73 | } |
| 74 | } |
| 75 | } else { |
| 76 | // validate the project if it really exists |
| 77 | if len(objs) > 0 { |
| 78 | for _, obj := range objs { |
| 79 | if obj.ID == project { |
| 80 | break |
| 81 | } |
| 82 | } |
| 83 | return LogError(fmt.Sprintf("Provided project (%s) does not exits in space cloud", project), nil) |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | acc, err := getSelectedAccount() |
| 88 | if err != nil { |
| 89 | return err |
| 90 | } |
| 91 | acc.DefaultProject = project |
| 92 | return StoreCredentials(acc) |
| 93 | } |
no test coverage detected