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:
Alec Thomas
2018-06-27 21:07:06 +10:00
parent 6408010083
commit 1bb0c0b4b2
9 changed files with 187 additions and 10 deletions
+2 -6
View File
@@ -24,7 +24,7 @@ type Tag struct {
Short rune
Hidden bool
Sep rune
Enum map[string]bool
Enum string
// Storage for all tag keys for arbitrary lookups.
items map[string]string
@@ -114,7 +114,6 @@ func parseTag(fv reflect.Value, ft reflect.StructField) *Tag {
s, chars := getTagInfo(ft)
t := &Tag{
items: parseTagItems(s, chars),
Enum: map[string]bool{},
}
t.Cmd = t.Has("cmd")
t.Arg = t.Has("arg")
@@ -149,10 +148,7 @@ func parseTag(fv reflect.Value, ft reflect.StructField) *Tag {
if t.PlaceHolder == "" {
t.PlaceHolder = strings.ToUpper(dashedString(fv.Type().Name()))
}
for _, part := range strings.Split(t.Get("enum"), ",") {
t.Enum[part] = true
}
t.Enum = t.Get("enum")
return t
}