-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.go
49 lines (38 loc) · 1.1 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package maker
import "fmt"
// Config stores the snippets required and any extra Maker setting
type Config struct {
Repositories []*Repository `yaml:"repositories"`
}
func (config *Config) AddRepository(repo *Repository) error {
if repo == nil {
return fmt.Errorf("no repository provided")
}
err := repo.Init()
if err != nil {
return err
}
// TODO lock before appending
config.Repositories = append(config.Repositories, repo)
return nil
}
// GetRepository returns a repository for the given reference, which can be
// either an alias or an URL. An empty reference returns the first
// (i.e. default) entry found in the configuration.
func (config *Config) GetRepository(reference string) (*Repository, error) {
if len(config.Repositories) == 0 {
return nil, fmt.Errorf("no repositories configured")
}
if reference == "" {
return config.Repositories[0], nil
}
for _, repository := range config.Repositories {
if repository.Alias == reference {
return repository, nil
}
if repository.URL == reference {
return repository, nil
}
}
return nil, fmt.Errorf("repository not found")
}