mirror of
https://github.com/beego/bee.git
synced 2024-11-22 10:10:53 +00:00
Displays the default value of a command flag
Added ability to display the default value of a command's flag, truncated in case it contains a column (:). Also instead of displaying the entire command usage/help in case of an undefined flag, output a small message with "bee help cmd".
This commit is contained in:
parent
73aa44e1a7
commit
ce71c916d5
16
bee.go
16
bee.go
@ -84,7 +84,7 @@ func (c *Command) Out() io.Writer {
|
||||
|
||||
// Usage puts out the usage for the command.
|
||||
func (c *Command) Usage() {
|
||||
tmpl(helpTemplate, c)
|
||||
tmpl(cmdUsage, c)
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
@ -97,7 +97,17 @@ func (c *Command) Runnable() bool {
|
||||
func (c *Command) Options() map[string]string {
|
||||
options := make(map[string]string)
|
||||
c.Flag.VisitAll(func(f *flag.Flag) {
|
||||
options[f.Name] = f.Usage
|
||||
defaultVal := f.DefValue
|
||||
if len(defaultVal) > 0 {
|
||||
if strings.Contains(defaultVal, ":") {
|
||||
// Truncate the flag's default value by appending '...' at the end
|
||||
options[f.Name+"="+strings.Split(defaultVal, ":")[0]+":..."] = f.Usage
|
||||
} else {
|
||||
options[f.Name+"="+defaultVal] = f.Usage
|
||||
}
|
||||
} else {
|
||||
options[f.Name] = f.Usage
|
||||
}
|
||||
})
|
||||
return options
|
||||
}
|
||||
@ -196,6 +206,8 @@ var errorTemplate = `bee: %s.
|
||||
Use {{"bee help" | bold}} for more information.
|
||||
`
|
||||
|
||||
var cmdUsage = `Use {{printf "bee help %s" .Name | bold}} for more information.{{endline}}`
|
||||
|
||||
func usage() {
|
||||
tmpl(usageTemplate, availableCommands)
|
||||
os.Exit(2)
|
||||
|
Loading…
Reference in New Issue
Block a user