-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
cloud_flags.go
55 lines (47 loc) · 1.23 KB
/
cloud_flags.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
package flag
import "time"
var (
cloudUpdateCacheFlag = Flag[bool]{
Name: "update-cache",
ConfigName: "cloud.update-cache",
Usage: "Update the cache for the applicable cloud provider instead of using cached results.",
}
cloudMaxCacheAgeFlag = Flag[time.Duration]{
Name: "max-cache-age",
ConfigName: "cloud.max-cache-age",
Default: time.Hour * 24,
Usage: "The maximum age of the cloud cache. Cached data will be required from the cloud provider if it is older than this.",
}
)
type CloudFlagGroup struct {
UpdateCache *Flag[bool]
MaxCacheAge *Flag[time.Duration]
}
type CloudOptions struct {
MaxCacheAge time.Duration
UpdateCache bool
}
func NewCloudFlagGroup() *CloudFlagGroup {
return &CloudFlagGroup{
UpdateCache: cloudUpdateCacheFlag.Clone(),
MaxCacheAge: cloudMaxCacheAgeFlag.Clone(),
}
}
func (f *CloudFlagGroup) Name() string {
return "Cloud"
}
func (f *CloudFlagGroup) Flags() []Flagger {
return []Flagger{
f.UpdateCache,
f.MaxCacheAge,
}
}
func (f *CloudFlagGroup) ToOptions() (CloudOptions, error) {
if err := parseFlags(f); err != nil {
return CloudOptions{}, err
}
return CloudOptions{
UpdateCache: f.UpdateCache.Value(),
MaxCacheAge: f.MaxCacheAge.Value(),
}, nil
}