/
common.go
37 lines (29 loc) · 957 Bytes
/
common.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
// Copyright 2015 Michal Witkowski. All Rights Reserved.
// See LICENSE for licensing terms.
package dflag
import (
"flag"
)
// DynamicFlagValue interface is a tag to know if a type is dynamic or not.
type DynamicFlagValue interface {
IsDynamicFlag() bool
}
// DynamicJSONFlagValue is a tag interface for JSON dynamic flags.
type DynamicJSONFlagValue interface {
IsJSON() bool
}
// DynamicFlagValueTag is a struct all dynamic flag inherit for marking they are dynamic.
type DynamicFlagValueTag struct{}
// IsDynamicFlag always returns true.
func (*DynamicFlagValueTag) IsDynamicFlag() bool {
return true
}
// A flag is dynamic if it implements DynamicFlagValue (which all the dyn* do)
// IsFlagDynamic returns whether the given Flag has been created in a Dynamic mode.
func IsFlagDynamic(f *flag.Flag) bool {
df, ok := f.Value.(DynamicFlagValue)
if !ok {
return false
}
return df.IsDynamicFlag() // will clearly return true if it exists
}