Add command arguments to help menu and don't show available options if there aren't any
This commit is contained in:
parent
9e6ca2ce76
commit
c6e41de5c8
18
help.go
18
help.go
|
@ -21,8 +21,17 @@ func (c *Command) ShowHelp() {
|
||||||
fmt.Print("<command> ")
|
fmt.Print("<command> ")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
fmt.Print("[options]")
|
||||||
fmt.Println("[options]")
|
if len(c.arguments) > 0 {
|
||||||
|
for _, a := range c.arguments {
|
||||||
|
if a.Required {
|
||||||
|
fmt.Print(" <" + a.Name + ">")
|
||||||
|
} else {
|
||||||
|
fmt.Print(" [" + a.Name + "]")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fmt.Println()
|
||||||
|
|
||||||
if len(c.subcommands) > 0 {
|
if len(c.subcommands) > 0 {
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
|
@ -38,19 +47,20 @@ func (c *Command) ShowHelp() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(c.opts) > 0 {
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
fmt.Println("Available options:")
|
fmt.Println("Available options:")
|
||||||
|
|
||||||
paddedWidth := c.opts.MaxWidth()
|
paddedWidth := c.opts.MaxWidth()
|
||||||
for _, f := range c.opts {
|
for _, f := range c.opts {
|
||||||
fmt.Println(" " + opt.HelpLine(f, paddedWidth))
|
fmt.Println(" " + opt.HelpLine(f, paddedWidth))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
globalOpts := opt.Globals()
|
globalOpts := opt.Globals()
|
||||||
if len(globalOpts) > 0 {
|
if len(globalOpts) > 0 {
|
||||||
paddedWidth = globalOpts.MaxWidth()
|
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
fmt.Println("Global options:")
|
fmt.Println("Global options:")
|
||||||
|
paddedWidth := globalOpts.MaxWidth()
|
||||||
for _, f := range globalOpts {
|
for _, f := range globalOpts {
|
||||||
fmt.Println(" " + opt.HelpLine(f, paddedWidth))
|
fmt.Println(" " + opt.HelpLine(f, paddedWidth))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue