primary

package
v0.0.0-...-2bc12df Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2021 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Action = Parser.add(&Primary{
	Description: "Returns true if the entry supports action",
	name:        "action",
	args:        "action",
	parseFunc: func(tokens []string) (types.EntryPredicate, []string, error) {
		if len(tokens) == 0 {
			return nil, nil, fmt.Errorf("requires additional arguments")
		}
		validActions := plugin.Actions()
		action, ok := validActions[tokens[0]]
		if !ok {

			validActionsArray := make([]string, 0, len(validActions))
			for actionName := range validActions {
				validActionsArray = append(validActionsArray, actionName)
			}
			validActionsStr := strings.Join(validActionsArray, ", ")
			return nil, nil, fmt.Errorf("%v is an invalid action. Valid actions are %v", tokens[0], validActionsStr)
		}
		p := types.ToEntryP(func(e types.Entry) bool {
			return e.Supports(action)
		})
		p.SetSchemaP(types.ToEntrySchemaP(func(s *types.EntrySchema) bool {
			for _, a := range s.Actions() {
				if action.Name == a {
					return true
				}
			}
			return false
		}))
		return p, tokens[1:], nil
	},
})

Action is the action primary

actionPrimary => <action> nolint

View Source
var Atime = newTimeAttrPrimary("atime")

Atime is the atime primary

nolint

View Source
var Crtime = newTimeAttrPrimary("crtime")

Crtime is the crtime primary

nolint

View Source
var Ctime = newTimeAttrPrimary("ctime")

Ctime is the ctime primary

nolint

View Source
var False = newBooleanPrimary(false)

False is the false primary

falsePrimary => -false nolint

View Source
var Kind = Parser.add(&Primary{
	Description:         "Returns true if the entry's kind matches pattern",
	DetailedDescription: kindDetailedDescription,
	name:                "kind",
	args:                "pattern",
	shortName:           "k",
	parseFunc: func(tokens []string) (types.EntryPredicate, []string, error) {
		if len(tokens) == 0 {
			return nil, nil, fmt.Errorf("requires additional arguments")
		}
		g, err := glob.Compile(tokens[0])
		if err != nil {
			return nil, nil, fmt.Errorf("invalid pattern: %v", err)
		}
		return kindP(g, false), tokens[1:], nil
	},
})

Kind is the kind primary

kindPrimary => -kind ShellPattern nolint

View Source
var Meta = Parser.add(&Primary{
	Description:         "Returns true if the entry's metadata satisfies the expression",
	DetailedDescription: metaDetailedDescription,
	name:                "meta",
	args:                "<expression>",
	shortName:           "m",
	parseFunc:           meta.Parse,
})

Meta is the meta primary

metaPrimary => (-meta|-m) Expression

Expression => EmptyPredicate | KeySequence PredicateExpression EmptyPredicate => -empty

KeySequence => '.' Key Tail Key => [ ^.[ ] ]+ (i.e. one or more cs that aren't ".", "[", or "]") Tail => '.' Key Tail |

‘[' ? ‘]’ Tail |
'[' * ']' Tail |
'[' N ']' Tail |
""

PredicateExpression => (See the comments of expression.Parser#Parse)

Predicate => ObjectPredicate |

ArrayPredicate      |
PrimitivePredicate

ObjectPredicate => EmptyPredicate | ‘.’ Key OAPredicate

ArrayPredicate => EmptyPredicate |

‘[' ? ‘]’ OAPredicate |
‘[' * ‘]’ OAPredicate |
‘[' N ‘]’ OAPredicate |

OAPredicate => Predicate | "(" PredicateExpression ")"

PrimitivePredicate => NullPredicate |

ExistsPredicate     |
BooleanPredicate    |
NumericPredicate    |
TimePredicate       |
StringPredicate

NullPredicate => -null ExistsPredicate => -exists BooleanPredicate => -true | -false

NumericPredicate => (+|-)? Number Number => N | '{' N '}' | numeric.SizeRegex

TimePredicate => (+|-)? Duration Duration => numeric.DurationRegex | '{' numeric.DurationRegex '}'

StringPredicate => [^-].*

N => \d+ (i.e. some number > 0)

nolint

View Source
var Mtime = newTimeAttrPrimary("mtime")

Mtime is the mtime primary

nolint

View Source
var Name = Parser.add(&Primary{
	Description: "Returns true if the entry's cname matches pattern",
	name:        "name",
	args:        "pattern",
	parseFunc: func(tokens []string) (types.EntryPredicate, []string, error) {
		if len(tokens) == 0 {
			return nil, nil, fmt.Errorf("requires additional arguments")
		}
		g, err := glob.Compile(tokens[0])
		if err != nil {
			return nil, nil, fmt.Errorf("invalid pattern: %v", err)
		}
		return types.ToEntryP(func(e types.Entry) bool {
			return g.Match(e.CName)
		}), tokens[1:], nil
	},
})

Name is the name primary

namePrimary => -name ShellPattern nolint

View Source
var Parser = &parser{
	primaryMap:   make(map[string]*Primary),
	SetPrimaries: make(map[*Primary]bool),
}

Parser parses `wash find` primaries.

View Source
var Path = Parser.add(&Primary{
	Description: "Returns true if the entry's normalized path matches pattern",
	name:        "path",
	args:        "pattern",
	parseFunc: func(tokens []string) (types.EntryPredicate, []string, error) {
		if len(tokens) == 0 {
			return nil, nil, fmt.Errorf("requires additional arguments")
		}
		g, err := glob.Compile(tokens[0])
		if err != nil {
			return nil, nil, fmt.Errorf("invalid pattern: %v", err)
		}
		return types.ToEntryP(func(e types.Entry) bool {
			return g.Match(e.NormalizedPath)
		}), tokens[1:], nil
	},
})

Path is the path primary

pathPrimary => -path ShellPattern nolint

View Source
var Size = Parser.add(&Primary{
	Description:         "Returns true if the entry's size attribute satisfies the given size predicate",
	DetailedDescription: sizeDetailedDescription,
	name:                "size",
	args:                "[+|-]n[ckMGTP]",
	parseFunc: func(tokens []string) (types.EntryPredicate, []string, error) {
		if len(tokens) == 0 {
			return nil, nil, fmt.Errorf("requires additional arguments")
		}
		numericP, parserID, err := numeric.ParsePredicate(
			tokens[0],
			numeric.ParsePositiveInt,
			numeric.ParseSize,
		)
		if err != nil {
			return nil, nil, fmt.Errorf("%v: illegal size value", tokens[0])
		}

		p := types.ToEntryP(func(e types.Entry) bool {
			if !e.Attributes.HasSize() {
				return false
			}
			size := int64(e.Attributes.Size())
			if parserID == 0 {

				size = int64(math.Ceil(float64(size) / 512.0))
			}
			return numericP(size)
		})
		return p, tokens[1:], nil
	},
})

Size is the size primary

sizePrimary => -size (+|-)?(\d+ | numeric.SizeRegex)

nolint

View Source
var True = newBooleanPrimary(true)

True is the true primary

truePrimary => -true nolint

Functions

func IsSet

func IsSet(p *Primary) bool

IsSet returns true if the specified primary was set Call this after `wash find` finishes parsing its arguments

func Table

func Table() *cmdutil.Table

Table returns a table containing all of `wash find`'s available primaries

Types

type Primary

type Primary struct {
	Description         string
	DetailedDescription string
	// contains filtered or unexported fields
}

Primary represents a `wash find` primary.

func Get

func Get(name string) *Primary

Get retrieves the specified primary

func (*Primary) Parse

func (primary *Primary) Parse(tokens []string) (predicate.Predicate, []string, error)

Parse parses a predicate from the given primary.

func (*Primary) Usage

func (primary *Primary) Usage() string

Usage returns the primary's usage string.

Directories

Path Synopsis
Package meta contains all the parsing logic for the `meta` primary
Package meta contains all the parsing logic for the `meta` primary

Jump to

Keyboard shortcuts

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