mow.cli: github.com/jawher/mow.cli/internal/matcher Index | Files | Directories

package matcher

import "github.com/jawher/mow.cli/internal/matcher"

Index

Package Files

arg.go context.go matchers.go option.go options.go optsEnd.go shortcut.go strings.go

func IsShortcut Uses

func IsShortcut(matcher Matcher) bool

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

type Matcher Uses

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 Uses

func NewArg(a *container.Container) Matcher

NewArg creates an (positional) argument matcher

func NewOpt Uses

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 Uses

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 Uses

func NewOptsEnd() Matcher

NewOptsEnd returns the special matcher that matches the -- operator

func NewShortcut Uses

func NewShortcut() Matcher

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

type ParseContext Uses

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 Uses

func NewParseContext() ParseContext

NewParseContext create a new ParseContext

func (ParseContext) Merge Uses

func (pc ParseContext) Merge(o ParseContext)

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

Directories

PathSynopsis
matchertest

Package matcher imports 3 packages (graph) and is imported by 4 packages. Updated 2019-06-20. Refresh now. Tools for package owners.