Drop (and fix) UsageFunc

pull/85/head v0.6.3
rwxrob 2 years ago
parent 7bcd340a40
commit a3b8f82b5e
No known key found for this signature in database
GPG Key ID: 2B9111F33082AE77

@ -96,14 +96,4 @@ type Command interface {
GetMaxParm() int
GetReqConf() bool
GetReqVars() bool
GetUsageFunc() UsageFunc
}
// UsageFunc allows dynamic creation of usage strings for interactive
// help and error messages. Every Z.Cmd has one as does the Z package
// itself (which defaults to InferredUsage). The Z package version is
// used with a Cmd has not assigned its own. UsageFunc should take the
// Command interface as the only argument, but it is acceptable for Cmd
// implementations to cast the Command passed to a specific Cmd to give
// that implementation access to rest of the Cmd symbol scope.
type UsageFunc func(x Command) string

@ -8,7 +8,7 @@ require (
github.com/rwxrob/scan v0.6.1
github.com/rwxrob/structs v0.5.1
github.com/rwxrob/term v0.2.6
github.com/rwxrob/to v0.4.6
github.com/rwxrob/to v0.5.2
)
require (

@ -12,6 +12,8 @@ github.com/rwxrob/to v0.4.5 h1:ILFn40Zd8Tbz0+vmMcA9WyBkAZzeIltr39STLeoxP/o=
github.com/rwxrob/to v0.4.5/go.mod h1:lojk6scni4ZRYjnKJO/f2DVRTW0BB6l9LZQ/NvZZt4Y=
github.com/rwxrob/to v0.4.6 h1:VXYmc2wI3aGq3HzecgMWYLiFZRVy1PlZIVOGRt0S8V0=
github.com/rwxrob/to v0.4.6/go.mod h1:lojk6scni4ZRYjnKJO/f2DVRTW0BB6l9LZQ/NvZZt4Y=
github.com/rwxrob/to v0.5.2 h1:BK2xKkWNhnR5TwEzbsPpXjGODFrTrgZfXzfEdtgCeyU=
github.com/rwxrob/to v0.5.2/go.mod h1:lojk6scni4ZRYjnKJO/f2DVRTW0BB6l9LZQ/NvZZt4Y=
golang.org/x/crypto v0.0.0-20220331220935-ae2d96664a29/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.0.0-20220408190544-5352b0902921 h1:iU7T1X1J6yxDr0rda54sWGkHgOp5XJrqm79gcNlC2VM=
golang.org/x/crypto v0.0.0-20220408190544-5352b0902921/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=

@ -98,10 +98,6 @@ var Conf bonzai.Configurer
// implementation to switch everything that depends on cached variables.
var Vars bonzai.CacheMap
// UsageText is used for one-line UsageErrors. It's exported to allow
// for different languages.
var UsageText = `usage`
// UsageFunc is the default first-class function called if a Cmd that
// does not already define its own when usage information is needed (see
// bonzai.UsageFunc and Cmd.UsageError for more). By default,
@ -110,10 +106,7 @@ var UsageText = `usage`
// It is used to return a usage summary. Generally, it should only
// return a single line (even if that line is very long). Developers
// are encouraged to refer users to their chosen help command rather
// than producing usually long usage lines. If only the word "usage"
// needs to be changed (for a given language) consider UsageText
// instead. Note that most developers will simply change the Usage
// string when they do not want the default inferred usage string.
// than producing usually long usage lines.
var UsageFunc = InferredUsage
// InferredUsage returns a single line of text summarizing only the

@ -37,10 +37,10 @@ type Cmd struct {
// run-time additions to main documentation (ex: {{ exename }})
Dynamic template.FuncMap `json:"-"`
// administrative URLs, "https://" assumed
Site string `json:"site,omitempty"` // template, landing page
// administrative URLs
Site string `json:"site,omitempty"` // template, https:// assumed
Source string `json:"source,omitempty"` // template, usually git url
Issues string `json:"issues,omitempty"` // template, have an issue
Issues string `json:"issues,omitempty"` // template, https:// assumed
// descending tree, completable
Commands []*Cmd `json:"commands,omitempty"`
@ -277,17 +277,9 @@ func (x *Cmd) Run() {
Exit()
}
// UsageError returns an error with a single-line usage string. The word
// "usage" can be changed by assigning Z.UsageText to something else.
// The commands own UsageFunc will be used if defined. If undefined, the
// Z.UsageFunc will be used instead (which can also be assigned
// to something else if needed).
// UsageError returns an error with a single-line usage string.
func (x *Cmd) UsageError() error {
usage := x.UsageFunc
if usage == nil {
usage = UsageFunc
}
return fmt.Errorf("%v: %v %v", UsageText, x.Name, usage(x))
return fmt.Errorf("usage: %v %v", x.Name, UsageFunc(x))
}
// ReqConfError returns stating that the given command requires that
@ -546,9 +538,6 @@ func (x *Cmd) GetReqConf() bool { return x.ReqConf }
// GetReqVars fulfills the bonzai.Command interface. No Fill.
func (x *Cmd) GetReqVars() bool { return x.ReqVars }
// GetUsageFunc fulfills the bonzai.Command interface. No Fill.
func (x *Cmd) GetUsageFunc() bonzai.UsageFunc { return x.UsageFunc }
// GetCommands fulfills the bonzai.Command interface.
func (x *Cmd) GetCommands() []bonzai.Command {
var commands []bonzai.Command

Loading…
Cancel
Save