Add VarDefsFromConf

main
Rob Muhlestein 2 years ago
parent 60020822cb
commit 494d2d684c

@ -124,6 +124,11 @@ var Vars bonzai.Vars
// than producing usually long usage lines.
var UsageFunc = InferredUsage
// VarDefsFromConf will cause the Get method to check for an existing
// Conf value matching the path as the and if found Set it to that
// default and then return it.
var VarDefsFromConf bool
// InferredUsage returns a single line of text summarizing only the
// Commands (less any Hidden commands), Params, and Aliases. If a Cmd
// is currently in an invalid state (Params without Call, no Call and no

@ -574,16 +574,33 @@ func (x *Cmd) C(q string) (string, error) {
}
// Get is a shorter version of Z.Vars.Get(x.Path()+"."+key) for
// convenience. Also see UseVars.
// convenience but also observes VarDefsFromConf if set. Also see
// UseVars.
func (x *Cmd) Get(key string) (string, error) {
if Vars == nil {
return "", UsesVars{x}
}
path := x.Path()
if path != "." {
path += "."
}
return Vars.Get(path + key), nil
ptr := path + key
v := Vars.Get(ptr)
if v != "" {
return v, nil
}
v, _ = Conf.Query(ptr)
if v != "" && v != "null" {
x.Set(key, v)
return v, nil
}
return "", nil
}
// Set is a shorter version of Z.Vars.Set(x.Path()+"."+key.val) for

Loading…
Cancel
Save