MCPcopy Index your code
hub / github.com/spacecloud-io/space-cloud / SetDefaultProject

Function SetDefaultProject

space-cli/cmd/utils/projects.go:59–93  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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
59func 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}

Callers 1

LoginStartFunction · 0.85

Calls 5

GetProjectsFromSCFunction · 0.85
LogErrorFunction · 0.85
getSelectedAccountFunction · 0.85
StoreCredentialsFunction · 0.85
AskOneMethod · 0.65

Tested by

no test coverage detected