{"modulePath":"github.com/keybase/cli","version":"v1.2.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package cli\n\nPackage cli provides a minimal framework for creating and organizing command line Go applications. cli is designed to be easy to understand and write, the most simple cli application can be written as follows:\n\n\tfunc main() {\n\t  cli.NewApp().Run(os.Args)\n\t}\n\nOf course this application does not do much, so let's make this an actual application:\n\n\tfunc main() {\n\t  app := cli.NewApp()\n\t  app.Name = \"greet\"\n\t  app.Usage = \"say a greeting\"\n\t  app.Action = func(c *cli.Context) {\n\t    println(\"Greetings\")\n\t  }\n\n\t  app.Run(os.Args)\n\t}\n\n## Variables\n\n```go\nvar AppHelpTemplate = `NAME:\n   {{.Name}} - {{.Usage}}\n\nUSAGE:\n   {{.Name}} {{ if .Flags }}[global options] {{ end }}command{{ if .Flags }} [command options]{{ end }} [arguments...]\n\nVERSION:\n   {{.Version}}\n\nCOMMANDS:\n   {{range .Commands}}{{.Name}}{{with .ShortName}}, {{.}}{{end}}{{ \"\\t\" }}{{.Usage}}\n   {{end}}{{ if .Flags }}\nGLOBAL OPTIONS:\n   {{range .Flags}}{{.}}\n   {{end}}{{ end }}\n`\n```\nThe text template for the Default help topic. cli.go uses text/template to render templates. You can render custom help text by setting this variable.\n\n```go\nvar BashCompletionFlag = BoolFlag{\n\tName: \"generate-bash-completion\",\n}\n```\nThis flag enables bash-completion for all commands and subcommands\n\n```go\nvar CommandHelpTemplate = `NAME:\n   {{.Name}} - {{.Usage}}\n\nUSAGE:\n   command {{.Name}}{{ if .Flags }} [command options]{{ end }} [arguments...]\n\nDESCRIPTION:\n   {{.Description}}{{ if .Flags }}\n\nOPTIONS:\n   {{range .Flags}}{{.}}\n   {{end}}{{ end }}\n`\n```\nThe text template for the command help topic. cli.go uses text/template to render templates. You can render custom help text by setting this variable.\n\n```go\nvar HelpFlag = BoolFlag{\n\tName:  \"help, h\",\n\tUsage: \"show help\",\n}\n```\nThis flag prints the help for all commands and subcommands\n\n```go\nvar HelpPrinter = printHelp\n```\nPrints help for the App\n\n```go\nvar SubcommandHelpTemplate = `NAME:\n   {{.Name}} - {{.Usage}}\n\nUSAGE:\n   {{.Name}} command{{ if .Flags }} [command options]{{ end }} [arguments...]\n\nCOMMANDS:\n   {{range .Commands}}{{.Name}}{{with .ShortName}}, {{.}}{{end}}{{ \"\\t\" }}{{.Usage}}\n   {{end}}{{ if .Flags }}\nOPTIONS:\n   {{range .Flags}}{{.}}\n   {{end}}{{ end }}\n`\n```\nThe text template for the subcommand help topic. cli.go uses text/template to render templates. You can render custom help text by setting this variable.\n\n```go\nvar VersionFlag = BoolFlag{\n\tName:  \"version, v\",\n\tUsage: \"print the version\",\n}\n```\nThis flag prints the version for the application\n\n## Functions\n\n```go\nfunc DefaultAppComplete(c *Context)\n```\nPrints the list of subcommands as the default app completion method\n\n```go\nfunc ShowAppHelp(c *Context)\n```\n\n```go\nfunc ShowCommandCompletions(ctx *Context, command string)\n```\nPrints the custom completions for a given command\n\n```go\nfunc ShowCommandHelp(c *Context, command string)\n```\nPrints help for the given command\n\n```go\nfunc ShowCompletions(c *Context)\n```\nPrints the lists of commands within a given context\n\n```go\nfunc ShowSubcommandHelp(c *Context)\n```\nPrints help for the given subcommand\n\n```go\nfunc ShowVersion(c *Context)\n```\nPrints the version number of the App\n\n## Types\n\n```go\ntype App struct {\n\t// The name of the program. Defaults to os.Args[0]\n\tName string\n\t// Description of the program.\n\tUsage string\n\t// Version of the program\n\tVersion string\n\t// List of commands to execute\n\tCommands []Command\n\t// List of flags to parse\n\tFlags []Flag\n\t// Boolean to enable bash completion commands\n\tEnableBashCompletion bool\n\t// Boolean to hide built-in help command\n\tHideHelp bool\n\t// An action to execute when the bash-completion flag is set\n\tBashComplete func(context *Context)\n\t// An action to execute before any subcommands are run, but after the context is ready\n\t// If a non-nil error is returned, no subcommands are run\n\tBefore func(context *Context) error\n\t// The action to execute when no subcommands are specified\n\tAction func(context *Context)\n\t// Execute this function if the proper command cannot be found\n\tCommandNotFound func(context *Context, command string)\n\t// Compilation date\n\tCompiled time.Time\n\t// Author\n\tAuthor string\n\t// Author e-mail\n\tEmail string\n}\n```\nApp is the main structure of a cli application. It is recomended that and app be created with the cli.NewApp() function\n\n```go\nfunc NewApp() *App\n```\nCreates a new cli Application with some reasonable defaults for Name, Usage, Version and Action.\n\n```go\nfunc (a *App) Command(name string) *Command\n```\nReturns the named command on App. Returns nil if the command does not exist\n\n```go\nfunc (a *App) Run(arguments []string) error\n```\nEntry point to the cli app. Parses the arguments slice and routes to the proper flag/args combination\n\n```go\nfunc (a *App) RunAndExitOnError()\n```\nAnother entry point to the cli app, takes care of passing arguments and error handling\n\n```go\nfunc (a *App) RunAsSubcommand(ctx *Context) error\n```\nInvokes the subcommand given the context, parses ctx.Args() to generate command-specific flags\n\n```go\ntype Args []string\n```\n\n```go\nfunc (a Args) First() string\n```\nReturns the first argument, or else a blank string\n\n```go\nfunc (a Args) Get(n int) string\n```\nReturns the nth argument, or else a blank string\n\n```go\nfunc (a Args) Present() bool\n```\nChecks if there are any arguments present\n\n```go\nfunc (a Args) Swap(from, to int) error\n```\nSwaps arguments at the given indexes\n\n```go\nfunc (a Args) Tail() []string\n```\nReturn the rest of the arguments (not the first one) or else an empty string slice\n\n```go\ntype BoolFlag struct {\n\tName   string\n\tUsage  string\n\tEnvVar string\n}\n```\n\n```go\nfunc (f BoolFlag) Apply(set *flag.FlagSet)\n```\n\n```go\nfunc (f BoolFlag) String() string\n```\n\n```go\ntype BoolTFlag struct {\n\tName   string\n\tUsage  string\n\tEnvVar string\n}\n```\n\n```go\nfunc (f BoolTFlag) Apply(set *flag.FlagSet)\n```\n\n```go\nfunc (f BoolTFlag) String() string\n```\n\n```go\ntype Command struct {\n\t// The name of the command\n\tName string\n\t// short name of the command. Typically one character\n\tShortName string\n\t// A short description of the usage of this command\n\tUsage string\n\t// A longer explanation of how the command works\n\tDescription string\n\t// The function to call when checking for bash command completions\n\tBashComplete func(context *Context)\n\t// An action to execute before any sub-subcommands are run, but after the context is ready\n\t// If a non-nil error is returned, no sub-subcommands are run\n\tBefore func(context *Context) error\n\t// The function to call when this command is invoked\n\tAction func(context *Context)\n\t// List of child commands\n\tSubcommands []Command\n\t// List of flags to parse\n\tFlags []Flag\n\t// Treat all flags as normal arguments if true\n\tSkipFlagParsing bool\n\t// Boolean to hide built-in help command\n\tHideHelp bool\n}\n```\nCommand is a subcommand for a cli.App.\n\n```go\nfunc (c Command) HasName(name string) bool\n```\nReturns true if Command.Name or Command.ShortName matches given name\n\n```go\nfunc (c Command) Run(ctx *Context) error\n```\nInvokes the command given the context, parses ctx.Args() to generate command-specific flags\n\n```go\ntype Context struct {\n\tApp     *App\n\tCommand Command\n\t// contains filtered or unexported fields\n}\n```\nContext is a type that is passed through to each Handler action in a cli application. Context can be used to retrieve context-specific Args and parsed command-line options.\n\n```go\nfunc NewContext(app *App, set *flag.FlagSet, globalSet *flag.FlagSet) *Context\n```\nCreates a new context. For use in when invoking an App or Command action.\n\n```go\nfunc (c *Context) Args() Args\n```\nReturns the command line arguments associated with the context.\n\n```go\nfunc (c *Context) Bool(name string) bool\n```\nLooks up the value of a local bool flag, returns false if no bool flag exists\n\n```go\nfunc (c *Context) BoolT(name string) bool\n```\nLooks up the value of a local boolT flag, returns false if no bool flag exists\n\n```go\nfunc (c *Context) Float64(name string) float64\n```\nLooks up the value of a local float64 flag, returns 0 if no float64 flag exists\n\n```go\nfunc (c *Context) Generic(name string) interface{}\n```\nLooks up the value of a local generic flag, returns nil if no generic flag exists\n\n```go\nfunc (c *Context) GlobalBool(name string) bool\n```\nLooks up the value of a global bool flag, returns false if no bool flag exists\n\n```go\nfunc (c *Context) GlobalGeneric(name string) interface{}\n```\nLooks up the value of a global generic flag, returns nil if no generic flag exists\n\n```go\nfunc (c *Context) GlobalInt(name string) int\n```\nLooks up the value of a global int flag, returns 0 if no int flag exists\n\n```go\nfunc (c *Context) GlobalIntSlice(name string) []int\n```\nLooks up the value of a global int slice flag, returns nil if no int slice flag exists\n\n```go\nfunc (c *Context) GlobalString(name string) string\n```\nLooks up the value of a global string flag, returns \"\" if no string flag exists\n\n```go\nfunc (c *Context) GlobalStringSlice(name string) []string\n```\nLooks up the value of a global string slice flag, returns nil if no string slice flag exists\n\n```go\nfunc (c *Context) Int(name string) int\n```\nLooks up the value of a local int flag, returns 0 if no int flag exists\n\n```go\nfunc (c *Context) IntSlice(name string) []int\n```\nLooks up the value of a local int slice flag, returns nil if no int slice flag exists\n\n```go\nfunc (c *Context) IsSet(name string) bool\n```\nDetermines if the flag was actually set exists\n\n```go\nfunc (c *Context) String(name string) string\n```\nLooks up the value of a local string flag, returns \"\" if no string flag exists\n\n```go\nfunc (c *Context) StringSlice(name string) []string\n```\nLooks up the value of a local string slice flag, returns nil if no string slice flag exists\n\n```go\ntype Flag interface {\n\tfmt.Stringer\n\t// Apply Flag settings to the given flag set\n\tApply(*flag.FlagSet)\n\t// contains filtered or unexported methods\n}\n```\nFlag is a common interface related to parsing flags in cli. For more advanced flag parsing techniques, it is recomended that this interface be implemented.\n\n```go\ntype Float64Flag struct {\n\tName   string\n\tValue  float64\n\tUsage  string\n\tEnvVar string\n}\n```\n\n```go\nfunc (f Float64Flag) Apply(set *flag.FlagSet)\n```\n\n```go\nfunc (f Float64Flag) String() string\n```\n\n```go\ntype Generic interface {\n\tSet(value string) error\n\tString() string\n}\n```\nGeneric is a generic parseable type identified by a specific flag\n\n```go\ntype GenericFlag struct {\n\tName   string\n\tValue  Generic\n\tUsage  string\n\tEnvVar string\n}\n```\nGenericFlag is the flag type for types implementing Generic\n\n```go\nfunc (f GenericFlag) Apply(set *flag.FlagSet)\n```\n\n```go\nfunc (f GenericFlag) String() string\n```\n\n```go\ntype IntFlag struct {\n\tName   string\n\tValue  int\n\tUsage  string\n\tEnvVar string\n}\n```\n\n```go\nfunc (f IntFlag) Apply(set *flag.FlagSet)\n```\n\n```go\nfunc (f IntFlag) String() string\n```\n\n```go\ntype IntSlice []int\n```\n\n```go\nfunc (f *IntSlice) Set(value string) error\n```\n\n```go\nfunc (f *IntSlice) String() string\n```\n\n```go\nfunc (f *IntSlice) Value() []int\n```\n\n```go\ntype IntSliceFlag struct {\n\tName   string\n\tValue  *IntSlice\n\tUsage  string\n\tEnvVar string\n}\n```\n\n```go\nfunc (f IntSliceFlag) Apply(set *flag.FlagSet)\n```\n\n```go\nfunc (f IntSliceFlag) String() string\n```\n\n```go\ntype StringFlag struct {\n\tName   string\n\tValue  string\n\tUsage  string\n\tEnvVar string\n}\n```\n\n```go\nfunc (f StringFlag) Apply(set *flag.FlagSet)\n```\n\n```go\nfunc (f StringFlag) String() string\n```\n\n```go\ntype StringSlice []string\n```\n\n```go\nfunc (f *StringSlice) Set(value string) error\n```\n\n```go\nfunc (f *StringSlice) String() string\n```\n\n```go\nfunc (f *StringSlice) Value() []string\n```\n\n```go\ntype StringSliceFlag struct {\n\tName   string\n\tValue  *StringSlice\n\tUsage  string\n\tEnvVar string\n}\n```\n\n```go\nfunc (f StringSliceFlag) Apply(set *flag.FlagSet)\n```\n\n```go\nfunc (f StringSliceFlag) String() string\n```\n\n","path":"github.com/keybase/cli","name":"cli","synopsis":"Package cli provides a minimal framework for creating and organizing command line Go applications.","isRedistributable":true}
