matcher

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 8, 2020 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsShortcut

func IsShortcut(matcher Matcher) bool

IsShortcut is a helper to determine whether a given matcher is a Shortcut (always matches)

Types

type Matcher

type Matcher interface {
	/* Match examines the provided args and:
	- likes it, fills the parse context and returns true and the remaining args it didn't consume
	- doesn't like it, returns false and  the remaining args it didn't consume
	*/
	Match(args []string, c *ParseContext) (bool, []string)
	// Priority used to sort matchers. the lower the returned number, the higher the priority of the matcher
	Priority() int
}

Matcher is used to parse and consume the args and populate the ParseContext

func NewArg

func NewArg(a *container.Container) Matcher

NewArg creates an (positional) argument matcher

func NewOpt

func NewOpt(o *container.Container, index map[string]*container.Container) Matcher

NewOpt create an option matcher that can consume short and long options

func NewOptions

func NewOptions(opts []*container.Container, index map[string]*container.Container) Matcher

NewOptions create an Options matcher which can parse a group of options

func NewOptsEnd

func NewOptsEnd() Matcher

NewOptsEnd returns the special matcher that matches the -- operator

func NewShortcut

func NewShortcut() Matcher

NewShortcut create a special matcher that always matches and doesn't consume any input

type ParseContext

type ParseContext struct {
	Args          map[*container.Container][]string
	Opts          map[*container.Container][]string
	ExcludedOpts  map[*container.Container]struct{}
	RejectOptions bool
}

ParseContext holds the state of the arguments parsing, i.e. the encountered options and arguments values, etc.

func NewParseContext

func NewParseContext() ParseContext

NewParseContext create a new ParseContext

func (ParseContext) Merge

func (pc ParseContext) Merge(o ParseContext)

Merge adds the values in the provided context in the current context

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL