mirror of
https://github.com/rwxrob/bonzai
synced 2024-11-14 18:12:59 +00:00
Add UsageError and MissingConf back
This commit is contained in:
parent
de68606750
commit
2075530694
6
z/cmd.go
6
z/cmd.go
@ -525,7 +525,6 @@ func (x *Cmd) Log(format string, a ...any) {
|
||||
// convenience. See UseConf.
|
||||
func (x *Cmd) C(q string) (string, error) {
|
||||
if Conf == nil {
|
||||
log.Printf("cmd %q requires a configurer (Z.Conf must be assigned)", x.Name)
|
||||
return "", UsesConf{x}
|
||||
}
|
||||
path := x.Path()
|
||||
@ -581,6 +580,11 @@ func (x *Cmd) Fill(tmpl string) string {
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
// UsageError returns IncorrectUsage for self.
|
||||
func (x *Cmd) UsageError() error {
|
||||
return IncorrectUsage{x}
|
||||
}
|
||||
|
||||
// --------------------- bonzai.Command interface ---------------------
|
||||
|
||||
// GetName fulfills the bonzai.Command interface. No Fill.
|
||||
|
@ -26,6 +26,14 @@ func (e WrongNumArgs) Error() string {
|
||||
return fmt.Sprintf("wrong number of args, %v required", e.Cmd.NumArgs)
|
||||
}
|
||||
|
||||
type MissingConf struct {
|
||||
Path string
|
||||
}
|
||||
|
||||
func (e MissingConf) Error() string {
|
||||
return fmt.Sprintf("missing conf value for %v", e.Path)
|
||||
}
|
||||
|
||||
type UsesConf struct {
|
||||
Cmd *Cmd
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user