Add support for setting variables via tag.
This provides much more convenient composition when reusing structs in
different parts of the command grammar.
eg.
type Embedded struct {
Key string `help:"A key from ${where}."`
}
var cli struct {
Embedded `set:"where=somewhere"`
}
This commit is contained in:
@@ -43,6 +43,7 @@ type Node struct {
|
||||
Positional []*Positional
|
||||
Children []*Node
|
||||
Target reflect.Value // Pointer to the value in the grammar that this Node is associated with.
|
||||
Tag *Tag
|
||||
|
||||
Argument *Value // Populated when Type is ArgumentNode.
|
||||
}
|
||||
@@ -171,6 +172,14 @@ func (n *Node) FullPath() string {
|
||||
return strings.TrimSpace(root.Name + " " + n.Path())
|
||||
}
|
||||
|
||||
// Vars returns the combined Vars defined by all ancestors of this Node.
|
||||
func (n *Node) Vars() Vars {
|
||||
if n == nil {
|
||||
return Vars{}
|
||||
}
|
||||
return n.Parent.Vars().CloneWith(n.Tag.Vars)
|
||||
}
|
||||
|
||||
// Path through ancestors to this Node.
|
||||
func (n *Node) Path() (out string) {
|
||||
if n.Parent != nil {
|
||||
|
||||
Reference in New Issue
Block a user