Skip to content

Commit bad7aca

Browse files
committed
Finish destroying newConfig
1 parent 18b2552 commit bad7aca

File tree

6 files changed

+603
-802
lines changed

6 files changed

+603
-802
lines changed

cli/bigcli/option.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/hashicorp/go-multierror"
77
"github.com/iancoleman/strcase"
88
"github.com/spf13/pflag"
9+
"golang.org/x/exp/maps"
910
"golang.org/x/xerrors"
1011
)
1112

@@ -14,8 +15,32 @@ import (
1415
const Disable = "-"
1516

1617
// Annotations is an arbitrary key-mapping used to extend the Option type.
18+
// Its methods won't panic if the map is nil.
1719
type Annotations map[string]string
1820

21+
// Mark sets a value on the attonations map, creating one
22+
// if it doesn't exist. Mark does not mutate the original and
23+
// returns a copy. It is suitable for chaining.
24+
func (a Annotations) Mark(key string, value string) Annotations {
25+
var aa Annotations
26+
if a != nil {
27+
aa = maps.Clone(a)
28+
} else {
29+
aa = make(Annotations)
30+
}
31+
a[key] = value
32+
return aa
33+
}
34+
35+
// IsSet returns true if the key is set in the annotations map.
36+
func (a Annotations) IsSet(key string) bool {
37+
if a == nil {
38+
return false
39+
}
40+
_, ok := a[key]
41+
return ok
42+
}
43+
1944
// Option is a configuration option for a CLI application.
2045
type Option struct {
2146
Name string

0 commit comments

Comments
 (0)