-
Notifications
You must be signed in to change notification settings - Fork 18
/
options.go
80 lines (65 loc) · 1.68 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
// SPDX-FileCopyrightText: 2022 SAP SE or an SAP affiliate company and Open Component Model contributors.
//
// SPDX-License-Identifier: Apache-2.0
package artifactset
import (
"github.com/open-component-model/ocm/pkg/common/accessio"
"github.com/open-component-model/ocm/pkg/errors"
)
type Options struct {
accessio.StandardOptions
FormatVersion string `json:"formatVersion,omitempty"`
}
func NewOptions(olist ...accessio.Option) (*Options, error) {
opts := &Options{}
err := accessio.ApplyOptions(opts, olist...)
if err != nil {
return nil, err
}
return opts, nil
}
type FormatVersionOption interface {
SetFormatVersion(string)
GetFormatVersion() string
}
func GetFormatVersion(opts accessio.Options) string {
if o, ok := opts.(FormatVersionOption); ok {
return o.GetFormatVersion()
}
return ""
}
var _ FormatVersionOption = (*Options)(nil)
func (o *Options) SetFormatVersion(s string) {
o.FormatVersion = s
}
func (o *Options) GetFormatVersion() string {
return o.FormatVersion
}
func (o *Options) ApplyOption(opts accessio.Options) error {
err := o.StandardOptions.ApplyOption(opts)
if err != nil {
return err
}
if o.FormatVersion != "" {
if s, ok := opts.(FormatVersionOption); ok {
s.SetFormatVersion(o.FormatVersion)
} else {
return errors.ErrNotSupported("format version option")
}
}
return nil
}
type optFmt struct {
format string
}
var _ accessio.Option = (*optFmt)(nil)
func StructureFormat(fmt string) accessio.Option {
return &optFmt{fmt}
}
func (o *optFmt) ApplyOption(opts accessio.Options) error {
if s, ok := opts.(FormatVersionOption); ok {
s.SetFormatVersion(o.format)
return nil
}
return errors.ErrNotSupported("format version option")
}