-
Notifications
You must be signed in to change notification settings - Fork 5.2k
/
gen_options_parser.go
67 lines (54 loc) · 1.44 KB
/
gen_options_parser.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package util
import (
"gopkg.in/yaml.v2"
"os"
)
type SourceOpts struct {
Strategy string `yaml:"strategy"`
}
type DestinationOpts struct {
Strategy string `yaml:"strategy"`
}
type ApplicationOpts struct {
Samples int `yaml:"samples"`
SourceOpts SourceOpts `yaml:"source"`
DestinationOpts DestinationOpts `yaml:"destination"`
}
type RepositoryOpts struct {
Samples int `yaml:"samples"`
}
type ProjectOpts struct {
Samples int `yaml:"samples"`
}
type ClusterOpts struct {
Samples int `yaml:"samples"`
NamespacePrefix string `yaml:"namespacePrefix"`
ValuesFilePath string `yaml:"valuesFilePath"`
DestinationNamespace string `yaml:"destinationNamespace"`
ClusterNamePrefix string `yaml:"clusterNamePrefix"`
Concurrency int `yaml:"parallel"`
}
type GenerateOpts struct {
ApplicationOpts ApplicationOpts `yaml:"application"`
ClusterOpts ClusterOpts `yaml:"cluster"`
RepositoryOpts RepositoryOpts `yaml:"repository"`
ProjectOpts ProjectOpts `yaml:"project"`
GithubToken string
Namespace string `yaml:"namespace"`
}
func setDefaults(opts *GenerateOpts) {
if opts.ClusterOpts.Concurrency == 0 {
opts.ClusterOpts.Concurrency = 2
}
}
func Parse(opts *GenerateOpts, file string) error {
fp, err := os.ReadFile(file)
if err != nil {
return err
}
if e := yaml.Unmarshal(fp, &opts); e != nil {
return e
}
setDefaults(opts)
return nil
}