Add command arguments to help menu and don't show available options if there aren't any

This commit is contained in:
Evan Fiordeliso 2023-11-12 17:22:17 -05:00
parent 9e6ca2ce76
commit c6e41de5c8
1 changed files with 19 additions and 9 deletions

28
help.go
View File

@ -21,8 +21,17 @@ func (c *Command) ShowHelp() {
fmt.Print("<command> ")
}
}
fmt.Println("[options]")
fmt.Print("[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 {
fmt.Println()
@ -38,19 +47,20 @@ func (c *Command) ShowHelp() {
}
}
fmt.Println()
fmt.Println("Available options:")
paddedWidth := c.opts.MaxWidth()
for _, f := range c.opts {
fmt.Println(" " + opt.HelpLine(f, paddedWidth))
if len(c.opts) > 0 {
fmt.Println()
fmt.Println("Available options:")
paddedWidth := c.opts.MaxWidth()
for _, f := range c.opts {
fmt.Println(" " + opt.HelpLine(f, paddedWidth))
}
}
globalOpts := opt.Globals()
if len(globalOpts) > 0 {
paddedWidth = globalOpts.MaxWidth()
fmt.Println()
fmt.Println("Global options:")
paddedWidth := globalOpts.MaxWidth()
for _, f := range globalOpts {
fmt.Println(" " + opt.HelpLine(f, paddedWidth))
}