2023-11-10 13:17:01 -05:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2023-11-10 15:11:50 -05:00
|
|
|
|
|
|
|
"go.fifitido.net/cmd/flags"
|
2023-11-10 13:17:01 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func (c *Command) ShowHelp() {
|
|
|
|
cmdPath := c.CommandPath()
|
|
|
|
|
|
|
|
fmt.Println(c.LongDescription)
|
|
|
|
fmt.Println()
|
|
|
|
fmt.Println("Usage: ")
|
|
|
|
fmt.Printf(" %s ", cmdPath)
|
|
|
|
|
|
|
|
if len(c.subcommands) > 0 {
|
|
|
|
if c.CanRun() {
|
|
|
|
fmt.Print("[command] ")
|
|
|
|
} else {
|
|
|
|
fmt.Print("<command> ")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println("[flags]")
|
|
|
|
|
|
|
|
if len(c.subcommands) > 0 {
|
|
|
|
fmt.Println()
|
|
|
|
|
|
|
|
if c.isRoot {
|
|
|
|
fmt.Println("Available commands:")
|
|
|
|
} else {
|
|
|
|
fmt.Println("Available subcommands:")
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, s := range c.subcommands {
|
|
|
|
fmt.Println(" " + s.Name + " " + s.ShortDescription)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println()
|
|
|
|
fmt.Println("Available flags:")
|
|
|
|
|
2023-11-10 15:11:50 -05:00
|
|
|
paddedWidth := c.flags.MaxWidth()
|
|
|
|
for _, f := range c.flags {
|
|
|
|
fmt.Println(" " + flags.HelpLine(f, paddedWidth))
|
2023-11-10 13:17:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println(" -h, --help Show the help menu")
|
|
|
|
fmt.Println(" -v, --version Show the app version")
|
|
|
|
|
|
|
|
if len(c.subcommands) > 0 {
|
|
|
|
fmt.Println()
|
|
|
|
fmt.Println("Run 'go-cli <command> --help' for more information about a command.")
|
|
|
|
}
|
|
|
|
}
|