54 lines
986 B
Go
54 lines
986 B
Go
|
package cmd
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
)
|
||
|
|
||
|
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:")
|
||
|
|
||
|
for _, s := range c.flags {
|
||
|
fmt.Println(" " + s.Name() + " " + s.Description())
|
||
|
}
|
||
|
|
||
|
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.")
|
||
|
}
|
||
|
}
|