Documentation
¶
Index ¶
- Constants
- func BashCompletionScript(command string) string
- func DefaultCompletion(opt *option.T, w string) []string
- func DefaultFilenameCompletion(opt *option.T, w string) (r []string)
- func MatchingFilenameCompletion(opt *option.T, pattern string, w string) (r []string)
- type Command
- type CompletionHandler
- type Handler
- type UsageHandler
- type VersionHandler
Constants ¶
const ErrCompletionRequested = errors.Sentinel("ErrCompletionRequested")
ErrCompletionRequested is a sentinel error indicating that the command was invoked in completion mode and that the completion options should be printed out instead of running the command
const ErrCompletionScriptRequested = errors.Sentinel("ErrCompletionScriptRequested")
ErrCompletionScriptRequested is a sentinel error indicating the bash completion script was requested and should be printed to stdout for evaluation
const ErrHelpRequested = errors.Sentinel("ErrHelpRequested")
ErrHelpRequested is a sentinel error indicating that help was requested with no explicit flag to handle the request
const ErrVersionRequested = errors.Sentinel("ErrVersionRequested")
ErrVersionRequested is a sentinel error indicating that version was requested with no explicit flag to handle the request
Variables ¶
This section is empty.
Functions ¶
func BashCompletionScript ¶
BashCompletionScript returns a string containing the bash script necessary to setup bash completion for the command.
func DefaultCompletion ¶
DefaultCompletion implements a default completion for a given option field, and can be used a fallback by command completion handlers. It handles specific cases based on the option field type, and simulates default shell behavior (filename completion) for string types.
func DefaultFilenameCompletion ¶ added in v0.5.0
DefaultFilenameCompletion implements a default filename-based completion, similar to the default shell completion.
Types ¶
type Command ¶
type Command struct { Handler Handler Description string ProcessName string ProcessArgs []string ProcessEnv map[string]string ConsoleWidth int DisableCompletion bool Suggestions []string // contains filtered or unexported fields }
Command is the representation of a runnable command, with reference to a runnable command attached to an options struct
func (*Command) Run ¶
Run is the main invocation point for a command. The command must be seeded with all the necessary runtime arguments from the process context (`ProcessName`, `ProcessArgs`, `ProcessEnv` and `ConsoleWidth`). It sets up the command option struct, applies the defaults abd environment variable, decodes the command-line and run the command.
func (*Command) SetProcessEnv ¶
SetProcessEnv sets the command `ProcessEnv` from a list of environment strings as returned by os.Environ().
type CompletionHandler ¶
CompletionHandler is an optional interface for the command handler to provide meaningful values for a specific option or argument.
type Handler ¶
type Handler interface {
Run() error
}
Handler defines the interface necessary to run a command once the command lien arguments have been parsed
type UsageHandler ¶
UsageHandler defines an optional interface for the command handler to print a custom usage message
type VersionHandler ¶
type VersionHandler interface {
Version() string
}
VersionHandler defines an optional interface for the command handler to return a relevant version string