Add Cmd.UsageError

This commit is contained in:
rwxrob 2022-02-24 18:14:12 -05:00
parent 107a091650
commit 3468bffaf0
No known key found for this signature in database
GPG Key ID: 2B9111F33082AE77

8
cmd.go
View File

@ -87,7 +87,7 @@ func (x *Cmd) Run() {
// seek should never fail to return something, but ...
cmd, args := x.Seek(os.Args[1:])
if cmd == nil {
ExitError("usage: %v %v\n", x.Name, x.Usage)
ExitError(x.UsageError())
}
// default to first Command if no Call defined
@ -102,7 +102,7 @@ func (x *Cmd) Run() {
}
Exit()
}
ExitError("usage: %v %v\n", x.Name, x.Usage)
ExitError(x.UsageError())
}
// delegate
@ -112,6 +112,10 @@ func (x *Cmd) Run() {
Exit()
}
func (x *Cmd) UsageError() error {
return fmt.Sprintf("usage: %v %v\n", x.Name, x.Usage)
}
// Add creates a new Cmd and sets the name and aliases and adds to
// Commands returning a reference to the new Cmd. The name must be
// first.