-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.go
More file actions
63 lines (54 loc) · 1.35 KB
/
Copy pathconfig.go
File metadata and controls
63 lines (54 loc) · 1.35 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package main
import (
"errors"
"flag"
"fmt"
"github.com/creasty/defaults"
"github.com/go-playground/validator/v10"
"gopkg.in/yaml.v3"
"os"
"strings"
)
type config struct {
Paths []string `yaml:"paths"`
Author authorConfig `yaml:"author"`
Files filesConf `yaml:"files"`
}
type filesConf struct {
IncludeRe string `yaml:"includeRe"`
ExcludeRe string `yaml:"excludeRe"`
}
type authorConfig struct {
Key string `yaml:"key" validate:"oneof=name mail" default:"name"`
Duplicates map[string][]string `yaml:"duplicates"`
}
var paths = flag.String("paths", "", "example: https://gitlab.int.tsum.com/preowned/simona/delta/customer-service.git, comma-separated")
var configPath = flag.String("conf", "gitlitics.yml", "path to config")
func parseConfig() (config, error) {
flag.Usage = func() {
fmt.Println("Use USER and PASSWORD for Git auth")
flag.PrintDefaults()
}
flag.Parse()
bytes, err := os.ReadFile(*configPath)
if err != nil && !errors.Is(err, os.ErrNotExist) {
return config{}, err
}
c := config{}
err = yaml.Unmarshal(bytes, &c)
if err != nil {
return config{}, err
}
err = defaults.Set(&c)
if err != nil {
return config{}, err
}
if paths != nil && len(*paths) != 0 {
c.Paths = strings.Split(*paths, ",")
}
err = validator.New().Struct(c)
if err != nil {
return config{}, err
}
return c, nil
}