github.com/billybanfield/evergreen@v0.0.0-20170525200750-eeee692790f7/model/cli.go (about) 1 package model 2 3 type ProjectConf struct { 4 Name string `json:"name" yaml:"name,omitempty"` 5 Default bool `json:"default" yaml:"default,omitempty"` 6 Variants []string `json:"variants" yaml:"variants,omitempty"` 7 Tasks []string `json:"tasks" yaml:"tasks,omitempty"` 8 } 9 10 // CLISettings represents the data stored in the user's config file, by default 11 // located at ~/.evergreen.yml 12 type CLISettings struct { 13 APIServerHost string `json:"api_server_host" yaml:"api_server_host,omitempty"` 14 UIServerHost string `json:"ui_server_host" yaml:"ui_server_host,omitempty"` 15 APIKey string `json:"api_key" yaml:"api_key,omitempty"` 16 User string `json:"user" yaml:"user,omitempty"` 17 Projects []ProjectConf `json:"projects" yaml:"projects,omitempty"` 18 LoadedFrom string `json:"-" yaml:"-"` 19 } 20 21 func (s *CLISettings) FindDefaultProject() string { 22 for _, p := range s.Projects { 23 if p.Default { 24 return p.Name 25 } 26 } 27 return "" 28 } 29 30 func (s *CLISettings) FindDefaultVariants(project string) []string { 31 for _, p := range s.Projects { 32 if p.Name == project { 33 return p.Variants 34 } 35 } 36 return nil 37 } 38 39 func (s *CLISettings) SetDefaultVariants(project string, variants ...string) { 40 for i, p := range s.Projects { 41 if p.Name == project { 42 s.Projects[i].Variants = variants 43 return 44 } 45 } 46 47 s.Projects = append(s.Projects, ProjectConf{project, true, variants, nil}) 48 } 49 50 func (s *CLISettings) FindDefaultTasks(project string) []string { 51 for _, p := range s.Projects { 52 if p.Name == project { 53 return p.Tasks 54 } 55 } 56 return nil 57 } 58 59 func (s *CLISettings) SetDefaultTasks(project string, tasks ...string) { 60 for i, p := range s.Projects { 61 if p.Name == project { 62 s.Projects[i].Tasks = tasks 63 return 64 } 65 } 66 67 s.Projects = append(s.Projects, ProjectConf{project, true, nil, tasks}) 68 } 69 70 func (s *CLISettings) SetDefaultProject(name string) { 71 var foundDefault bool 72 for i, p := range s.Projects { 73 if p.Name == name { 74 s.Projects[i].Default = true 75 foundDefault = true 76 } else { 77 s.Projects[i].Default = false 78 } 79 } 80 81 if !foundDefault { 82 s.Projects = append(s.Projects, ProjectConf{name, true, []string{}, []string{}}) 83 } 84 }