-
Notifications
You must be signed in to change notification settings - Fork 20
/
options.go
171 lines (132 loc) · 3.36 KB
/
options.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
package helm
import (
"github.com/mandelsoft/goutils/optionutils"
"github.com/mandelsoft/vfs/pkg/vfs"
"github.com/open-component-model/ocm/pkg/common"
"github.com/open-component-model/ocm/pkg/contexts/oci"
"github.com/open-component-model/ocm/pkg/utils"
)
type Option = optionutils.Option[*Options]
type Options struct {
Context oci.Context
FileSystem vfs.FileSystem
Version string
OverrideVersion *bool
HelmRepository string
CACert string
CACertFile string
Printer common.Printer
}
func (o *Options) ApplyTo(opts *Options) {
if opts == nil {
return
}
if o.Context != nil {
opts.Context = o.Context
}
if o.FileSystem != nil {
opts.FileSystem = o.FileSystem
}
if o.Version != "" {
opts.Version = o.Version
}
if o.OverrideVersion != nil {
opts.OverrideVersion = o.OverrideVersion
}
if o.HelmRepository != "" {
opts.HelmRepository = o.HelmRepository
}
if o.CACert != "" {
opts.CACert = o.CACert
}
if o.CACertFile != "" {
opts.CACertFile = o.CACertFile
}
if o.Printer != nil {
opts.Printer = o.Printer
}
}
func (o *Options) OCIContext() oci.Context {
if o.Context == nil {
return oci.DefaultContext()
}
return o.Context
}
////////////////////////////////////////////////////////////////////////////////
type context struct {
oci.Context
}
func (o context) ApplyTo(opts *Options) {
opts.Context = o
}
func WithContext(ctx oci.ContextProvider) Option {
return context{ctx.OCIContext()}
}
////////////////////////////////////////////////////////////////////////////////
type fileSystem struct {
fs vfs.FileSystem
}
func (o *fileSystem) ApplyTo(opts *Options) {
opts.FileSystem = o.fs
}
func WithFileSystem(fs vfs.FileSystem) Option {
return &fileSystem{fs: fs}
}
////////////////////////////////////////////////////////////////////////////////
type version string
func (o version) ApplyTo(opts *Options) {
opts.Version = string(o)
}
func WithVersion(v string) Option {
return version(v)
}
////////////////////////////////////////////////////////////////////////////////
type override struct {
flag bool
version string
}
func (o *override) ApplyTo(opts *Options) {
opts.OverrideVersion = utils.BoolP(o.flag)
opts.Version = o.version
}
func WithVersionOverride(v string, flag ...bool) Option {
return &override{
version: v,
flag: utils.OptionalDefaultedBool(true, flag...),
}
}
////////////////////////////////////////////////////////////////////////////////
type helmrepo string
func (o helmrepo) ApplyTo(opts *Options) {
opts.HelmRepository = string(o)
}
// WithHelmRepository defines the helm repository to read from.
func WithHelmRepository(v string) Option {
return helmrepo(v)
}
////////////////////////////////////////////////////////////////////////////////
type cacert string
func (o cacert) ApplyTo(opts *Options) {
opts.CACert = string(o)
}
func WithCACert(v string) Option {
return cacert(v)
}
////////////////////////////////////////////////////////////////////////////////
type cacertfile string
func (o cacertfile) ApplyTo(opts *Options) {
opts.CACertFile = string(o)
}
func WithCACertFile(v string) Option {
return cacertfile(v)
}
////////////////////////////////////////////////////////////////////////////////
type printer struct {
common.Printer
}
func (o printer) ApplyTo(opts *Options) {
opts.Printer = o
}
func WithPrinter(p common.Printer) Option {
return printer{p}
}