Add UsageError and MissingConf back

This commit is contained in:
rwxrob 2022-04-14 10:33:47 -04:00
parent de68606750
commit 2075530694
No known key found for this signature in database
GPG Key ID: 2B9111F33082AE77
2 changed files with 13 additions and 1 deletions

View File

@ -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.

View File

@ -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
}