Support limited variable interpolation.
Kong supports limited variable interpolation into help strings, enum lists and
default values.
Variables are in the form:
${<name>}
Variables are set with the `Vars(map[string]string)` option. Undefined
variable references in the grammar will result in an error at construction
time.
This commit is contained in:
@@ -185,10 +185,11 @@ func (n *Node) Path() (out string) {
|
||||
|
||||
// A Value is either a flag or a variable positional argument.
|
||||
type Value struct {
|
||||
Flag *Flag
|
||||
Flag *Flag // Nil if positional argument.
|
||||
Name string
|
||||
Help string
|
||||
Default string
|
||||
Enum string
|
||||
Mapper Mapper
|
||||
Tag *Tag
|
||||
Target reflect.Value
|
||||
@@ -198,6 +199,16 @@ type Value struct {
|
||||
Position int // Position (for positional arguments).
|
||||
}
|
||||
|
||||
// EnumMap returns a map of the enums in this value.
|
||||
func (v *Value) EnumMap() map[string]bool {
|
||||
parts := strings.Split(v.Enum, ",")
|
||||
out := make(map[string]bool, len(parts))
|
||||
for _, part := range parts {
|
||||
out[strings.TrimSpace(part)] = true
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// Summary returns a human-readable summary of the value.
|
||||
func (v *Value) Summary() string {
|
||||
if v.Flag != nil {
|
||||
|
||||
Reference in New Issue
Block a user