-
Notifications
You must be signed in to change notification settings - Fork 19
/
options.go
105 lines (80 loc) · 2.03 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
package dockermulti
import (
"github.com/mandelsoft/goutils/optionutils"
"golang.org/x/exp/slices"
"github.com/open-component-model/ocm/pkg/common"
"github.com/open-component-model/ocm/pkg/contexts/oci"
)
type Option = optionutils.Option[*Options]
type Options struct {
Context oci.Context
Version string
Variants []string
Origin *common.NameVersion
Printer common.Printer
}
func (o *Options) ApplyTo(opts *Options) {
if opts == nil {
return
}
if o.Context != nil {
opts.Context = o.Context
}
if o.Version != "" {
opts.Version = o.Version
}
if o.Variants != nil {
opts.Variants = append(opts.Variants, o.Variants...)
}
if o.Origin != nil {
opts.Origin = o.Origin
}
if o.Printer != nil {
opts.Printer = o.Printer
}
}
////////////////////////////////////////////////////////////////////////////////
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 version string
func (o version) ApplyTo(opts *Options) {
opts.Version = string(o)
}
func WithVersion(v string) Option {
return version(v)
}
////////////////////////////////////////////////////////////////////////////////
type compvers common.NameVersion
func (o compvers) ApplyTo(opts *Options) {
n := common.NameVersion(o)
opts.Origin = &n
}
func WithOrigin(o common.NameVersion) Option {
return compvers(o)
}
////////////////////////////////////////////////////////////////////////////////
type variants []string
func (o variants) ApplyTo(opts *Options) {
opts.Variants = append(opts.Variants, []string(o)...)
}
func WithVariants(v ...string) Option {
return variants(slices.Clone(v))
}
////////////////////////////////////////////////////////////////////////////////
type printer struct {
common.Printer
}
func (o printer) ApplyTo(opts *Options) {
opts.Printer = o
}
func WithPrinter(p common.Printer) Option {
return printer{p}
}