Documentation ¶
Index ¶
- Constants
- func FindChildren(commands *group.Group, prefix string, includeSubKeys bool) (map[string]Command, error)
- type AutoCompleter
- type CLI
- type CLIOption
- type CLIOptions
- type Command
- type CommandFn
- type Errno
- type GlobalArgs
- func (a *GlobalArgs) CommandFlags() []string
- func (a *GlobalArgs) Debug() bool
- func (a *GlobalArgs) DevMode() bool
- func (a *GlobalArgs) Help() bool
- func (a *GlobalArgs) Process(args []string) error
- func (a *GlobalArgs) RequiresInstall() bool
- func (a *GlobalArgs) RequiresNoColor() bool
- func (a *GlobalArgs) RequiresNoSubKeys() bool
- func (a *GlobalArgs) RequiresUninstall() bool
- func (a *GlobalArgs) SubCommand() string
- func (a *GlobalArgs) SubCommandArgs() []string
- func (a *GlobalArgs) SubCommandFlags() []string
- func (a *GlobalArgs) Version() bool
- type UI
Constants ¶
const TemplateComplete = `
{{- range $name := .}}
{{ $name }}
{{- end}}
`
TemplateComplete describes a template for rendering autocomplete commands.
const TemplateFlags = `
{{.Name}} {{.Usage}} (defaults: "{{.Defaults}}")
`
TemplateFlags describes a template for rendering flags in help.
const TemplatePlaceHolder = `
Selection of commands that are nested under this one.
`
TemplatePlaceHolder describes a template for rendering placeholder text.
const TemplateVersion = `
Client version: {{ .Version }}
`
TemplateVersion describes a template for rendering version.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AutoCompleter ¶
type AutoCompleter interface { // Complete a command from completion line in environment variable, // and print out the complete options. // Returns success if the completion ran or if the cli matched // any of the given flags, false otherwise Complete(string) ([]string, bool) // Install a command into the host using the Installer. // Returns an error if there is an error whilst installing. Install(string) error // Uninstall the command from the host using the Installer. // Returns an error if there is an error whilst it's uninstalling. Uninstall(string) error }
AutoCompleter is an interface to be implemented to perform the autocomplete installation and un-installation with a CLI.
This interface is not exported because it only exists for unit tests to be able to test that the installation is called properly.
type CLI ¶
type CLI struct {
// contains filtered or unexported fields
}
CLI contains the state necessary to run commands and parse the command line arguments
CLI also supports nested subCommands, such as "cli foo bar". To use nested subCommands, the key in the Commands mapping below contains the full subCommand. In this example, it would be "foo bar"
type CLIOption ¶
type CLIOption func(CLIOptions)
CLIOption captures a tweak that can be applied to the CLI.
func OptionAutoCompleter ¶
func OptionAutoCompleter(i AutoCompleter) CLIOption
OptionAutoCompleter allows the setting a AutoCompleter option to configure the cli.
func OptionFileSystem ¶
func OptionFileSystem(i fsys.FileSystem) CLIOption
OptionFileSystem allows the setting a FileSystem option to configure the cli.
func OptionHelpFunc ¶
OptionHelpFunc allows the setting a HelpFunc option to configure the cli.
type CLIOptions ¶
type CLIOptions interface { SetHelpFunc(help.Func) SetAutoCompleter(AutoCompleter) SetUI(UI) SetFileSystem(fsys.FileSystem) }
CLIOptions represents a way to set optional values to a CLI option. The CLIOptions shows what options are available to change.
type Command ¶
type Command interface { // Flags returns the FlagSet associated with the command. All the flags are // parsed before running the command. FlagSet() *flagset.FlagSet // Usages returns various usages that can be used for the command. Usages() []string // Help should return a long-form help text that includes the command-line // usage. A brief few sentences explaining the function of the command, and // the complete list of flags the command accepts. Help() string // Synopsis should return a one-line, short synopsis of the command. // This should be short (50 characters of less ideally). Synopsis() string // Init is called with all the args required to run a command. // This is separated from Run, to allow the preperation of a command, before // it's run. Init([]string, commands.CommandContext) error // Run should run the actual command with the given CLI instance and // command-line arguments. It should return the exit status when it is // finished. // // There are a handful of special exit codes that can return documented // behavioral changes. Run(*task.Group) }
Command is a runnable sub-command of CLI.
type GlobalArgs ¶
type GlobalArgs struct {
// contains filtered or unexported fields
}
GlobalArgs is used to construct the arguments used for the CLI. The global arguments are then passed to the command once found, without the global flags.
func NewGlobalArgs ¶
func NewGlobalArgs(commands *group.Group) *GlobalArgs
NewGlobalArgs creates a new GlobalArgs type for processing arguments passed to the cli.
func (*GlobalArgs) CommandFlags ¶
func (a *GlobalArgs) CommandFlags() []string
CommandFlags returns the command arguments.
func (*GlobalArgs) Debug ¶
func (a *GlobalArgs) Debug() bool
Debug returns if the operator has passed the debug flag.
func (*GlobalArgs) DevMode ¶
func (a *GlobalArgs) DevMode() bool
DevMode returns if the operator has passed the devMode flag.
func (*GlobalArgs) Help ¶
func (a *GlobalArgs) Help() bool
Help returns if the operator has passed the help flag.
func (*GlobalArgs) Process ¶
func (a *GlobalArgs) Process(args []string) error
Process consumes the arguments and correctly separates them between global flags and arguments and command flags and arguments.
func (*GlobalArgs) RequiresInstall ¶
func (a *GlobalArgs) RequiresInstall() bool
RequiresInstall returns if the operator has passed the requires install flag.
func (*GlobalArgs) RequiresNoColor ¶
func (a *GlobalArgs) RequiresNoColor() bool
RequiresNoColor returns if the operator has passed the no color output flag.
func (*GlobalArgs) RequiresNoSubKeys ¶
func (a *GlobalArgs) RequiresNoSubKeys() bool
RequiresNoSubKeys returns if the help should include subkeys.
func (*GlobalArgs) RequiresUninstall ¶
func (a *GlobalArgs) RequiresUninstall() bool
RequiresUninstall returns if the operator has passed the requires uninstall flag.
func (*GlobalArgs) SubCommand ¶
func (a *GlobalArgs) SubCommand() string
SubCommand returns the sub command name.
func (*GlobalArgs) SubCommandArgs ¶
func (a *GlobalArgs) SubCommandArgs() []string
SubCommandArgs returns the sub command arguments.
func (*GlobalArgs) SubCommandFlags ¶
func (a *GlobalArgs) SubCommandFlags() []string
SubCommandFlags returns the sub command flags.
func (*GlobalArgs) Version ¶
func (a *GlobalArgs) Version() bool
Version returns if the operator has passed the version flag.
type UI ¶
type UI interface { // Ask asks the user for input using the given query. The response is // returned as the given string, or an error. Ask(string) (string, error) // AskSecret asks the user for input using the given query, but does not echo // the keystrokes to the terminal. AskSecret(string) (string, error) // Output is called for normal standard output. Output(*ui.Template, interface{}) error // Info is called for information related to the previous output. // In general this may be the exact same as Output, but this gives // UI implementors some flexibility with output formats. Info(string) // Error is used for any error messages that might appear on standard // error. Error(string) }
UI is an interface for interacting with the terminal, or "interface" of a CLI.