Documentation ¶
Overview ¶
Package cli is a very minimal framework for creating command line applications.
cli only supports boolean flags and top level commands, which is all that gomake needs. We can write a simple greeter like so:
package main import ( "fmt" "os" "github.com/hinshun/gomake/pkg/cli" ) func main() { app := cli.App{ Name: "greeter", Action: func(ctx *cli.Context) error { fmt.Println("hello") return nil }, } app.Run(os.Args) }
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // HelpFlag is the flag to display the App's help text HelpFlag = &Flag{ Name: "help", Aliases: []string{"h"}, Description: "show help", } // VersionFlag is the flag to display the App's version text VersionFlag = &Flag{ Name: "version", Aliases: []string{"v"}, Description: "print the version", } )
View Source
var ( // ErrIncorrectUsage is returned when the App is ran with bad arguments. ErrIncorrectUsage = errors.New("incorrect usage") )
Functions ¶
func ParseFlags ¶
ParseFlags parses the args and returns a map of flags set.
Types ¶
type App ¶
type App struct { // Name is the name of the program. Name string // Version is the version of the program. Version string // Action is the default action to execute when no subcommands are specified. Action Action // Commands is the list of subcommands the program can run. Commands Commands // Flags is the list of boolean flags that can be enabled. Flags Flags }
App is a simple cli application.
func (*App) ShowVersion ¶
func (a *App) ShowVersion()
ShowHelp displays the version text for the App.
type Command ¶
type Command struct { // Name is the name of the subcommand. Name string // Description is a brief text about the subcommand. Description string // Action is the function to call when the command is invoked. Action Action }
Command is a subcommand for an App.
type Commands ¶
type Commands []*Command
Commands is a sortable list of commands.
func (Commands) ActionForName ¶
type Context ¶
type Context struct { // Action is the context wrapped function to be evaluated. Action func() error // contains filtered or unexported fields }
Context is the context is which an Action is ran.
func NewContext ¶
NewContext initializes a new context for the Action to run in.
type Flag ¶
type Flag struct { // Name is the name of this flag. Name string // Aliases is the list of alternate names to enable the flag. Aliases []string // Description is a brief text of what the flag enables. Description string }
Flag is a boolean flag that gets passed down to the action called.
Click to show internal directories.
Click to hide internal directories.