cmd/help.go

57 lines
1.0 KiB
Go

package cmd
import (
"fmt"
"go.fifitido.net/cmd/flags"
)
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:")
paddedWidth := c.flags.MaxWidth()
for _, f := range c.flags {
fmt.Println(" " + flags.HelpLine(f, paddedWidth))
}
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.")
}
}