Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidBundleCommandPair is returned by FindCommandEntry when the // command entry string doesn't look like "command" or "bundle:command". ErrInvalidBundleCommandPair = errors.New("invalid bundle:comand pair") )
Functions ¶
func SplitCommand ¶
SplitCommand accepts a string in the style of "bundle:command" or "command" and returns the bundle and command as a pair of strings. If there's no indicated bundle, the bundle string (the first string) will be empty. If there's more than one colon, an error will be returned.
func Tokenize ¶
Tokenize takes an input string and splits it into tokens. Any control character sequences ("\n", "\t", etc), pass through in their original form. Examples:
echo -n foo bar -> {"echo", "-n", "foo", "bar"} echo -n "foo bar" -> {"echo", "-n", "foo bar"} echo "What's" "\"this\"?" -> {"echo", "What's", "\"this\"?"}
Types ¶
type Command ¶
type Command struct { Bundle string Command string Options map[string]CommandOption Parameters CommandParameters }
Command represents a command typed in by a user. It is typically generated by the Parse function.
func Parse ¶
func Parse(tokens []string, options ...ParseOption) (Command, error)
Parse accepts a slice of token strings and constructs a Command value. Its behavior may be modified by passing one or more ParseOptions.
func TokenizeAndParse ¶
func TokenizeAndParse(str string, options ...ParseOption) (Command, error)
TokenizeAndParse is a helper function that combines the Tokenize and Parse functions.
type CommandOption ¶
CommandOption represents a command option or flag, and its string value (if any).
type CommandParameters ¶
func (CommandParameters) String ¶
func (c CommandParameters) String() string
type ParseOption ¶
type ParseOption func(*parseOptions)
func ParseAgnosticDashes ¶
func ParseAgnosticDashes(agnostic bool) ParseOption
ParseAgnosticDashes modifies how dashes are interpreted. If true, double and single dashes are treated the same. If false (default), then double-dashed options are "long" and single-dashed options are "short".
func ParseAssumeOptionArguments ¶
func ParseAssumeOptionArguments(assume bool) ParseOption
ParseAssumeOptionArguments changes the assumption about whether an option not specified using ParseOptionHasArgument should be treated as having an option. If false (default), unknown options are assumed to have no argument.
func ParseOptionAlias ¶
func ParseOptionAlias(alias, name string) ParseOption
ParseOptionAlias allows option aliases to be set, most often "short options" to "long options". All references to "alias" are treated as "name".
func ParseOptionHasArgument ¶
func ParseOptionHasArgument(option string, hasArg bool) ParseOption
ParseOptionHasArgument allows specific options to be specified as expecting an option (or not). Options not specified are treated according to ParseAssumeOptionArguments.
type TokenizeError ¶
func (TokenizeError) Error ¶
func (e TokenizeError) Error() string