mirror of
https://github.com/rwxrob/bonzai
synced 2024-11-12 07:10:26 +00:00
Fix Cmd.Q, tighten Query interface reqs
This commit is contained in:
parent
fa90cf0850
commit
a3e22c48f8
@ -24,6 +24,11 @@ package bonzai
|
||||
// to OverWrite will be marshalled to YAML and completely replace the
|
||||
// existing configuration in a way that must guarantee atomic,
|
||||
// system-wide write safety. (Locking a file is insufficient alone.)
|
||||
//
|
||||
// Query implementations must trim any initial or trailing white space
|
||||
// (usually just a single line return from yq, for example) in order to
|
||||
// ensure that the resulting values for edge matches can be used without
|
||||
// needing a trim.
|
||||
type Configurer interface {
|
||||
Init() error // must initialize a new configuration
|
||||
Data() string // must return full YAML
|
||||
|
9
z/cmd.go
9
z/cmd.go
@ -408,11 +408,12 @@ func (x *Cmd) Path() []string {
|
||||
return path.Items()
|
||||
}
|
||||
|
||||
// PathString returns a dotted notation of the Path. This is useful for
|
||||
// associating configuration and other data specifically with this
|
||||
// PathString returns a dotted notation of the Path including an initial
|
||||
// dot (for root). This is compatible yq query expressions and useful
|
||||
// for associating configuration and other data specifically with this
|
||||
// command.
|
||||
func (x *Cmd) PathString() string {
|
||||
return strings.Join(x.Path(), ".")
|
||||
return "." + strings.Join(x.Path(), ".")
|
||||
}
|
||||
|
||||
// Log is currently short for log.Printf() but may be supplemented in
|
||||
@ -421,7 +422,7 @@ func (x *Cmd) Log(format string, a ...any) {
|
||||
log.Printf(format, a...)
|
||||
}
|
||||
|
||||
// Q is a shorter version of Z.Conf.Query(x.Path()+"."+q) for
|
||||
// Q is a shorter version of Z.Conf.Query(x.PathString()+"."+q) for
|
||||
// convenience. Logs the error and returns a blank string if Z.Conf is
|
||||
// not defined (see ReqConf).
|
||||
func (x *Cmd) Q(q string) string {
|
||||
|
@ -135,7 +135,7 @@ func ExampleCmd_PathString() {
|
||||
z.Run()
|
||||
|
||||
// Output:
|
||||
// some.thing.deep
|
||||
// .some.thing.deep
|
||||
}
|
||||
|
||||
func ExampleCmd_Names() {
|
||||
|
Loading…
Reference in New Issue
Block a user