Documentation ¶
Overview ¶
Package filters provides helper function to parse and handle command line filter, used for example in docker ps or docker images commands.
Index ¶
- Variables
- func ToParam(a Args) (string, error)
- type Args
- func (filters Args) Add(name, value string)
- func (filters Args) Del(name, value string)
- func (filters Args) ExactMatch(field, source string) bool
- func (filters Args) Get(field string) []string
- func (filters Args) Include(field string) bool
- func (filters Args) Len() int
- func (filters Args) Match(field, source string) bool
- func (filters Args) MatchKVList(field string, sources map[string]string) bool
- func (filters Args) Validate(accepted map[string]bool) error
- func (filters Args) WalkValues(field string, op func(value string) error) error
Constants ¶
This section is empty.
Variables ¶
var ErrBadFormat = errors.New("bad format of filter (expected name=value)")
ErrBadFormat is an error returned in case of bad format for a filter.
Functions ¶
Types ¶
type Args ¶
type Args struct {
// contains filtered or unexported fields
}
Args stores filter arguments as map key:{array of values}. It contains a aggregation of the list of arguments (which are in the form of -f 'key=value') based on the key, and store values for the same key in an slice. e.g given -f 'label=label1=1' -f 'label=label2=2' -f 'image.name=ubuntu' the args will be {'label': {'label1=1','label2=2'}, 'image.name', {'ubuntu'}}
func ParseFlag ¶
ParseFlag parses the argument to the filter flag. Like
`docker ps -f 'created=today' -f 'image.name=ubuntu*'`
If prev map is provided, then it is appended to, and returned. By default a new map is created.
func (Args) ExactMatch ¶
ExactMatch returns true if the source matches exactly one of the filters.
func (Args) Get ¶
Get returns the list of values associates with a field. It returns a slice of strings to keep backwards compatibility with old code.
func (Args) Match ¶
Match returns true if the values for the specified field matches the source string e.g. given Args are {'label': {'label1=1','label2=1'}, 'image.name', {'ubuntu'}},
field is 'image.name' and source is 'ubuntu' it returns true.
func (Args) MatchKVList ¶
MatchKVList returns true if the values for the specified field maches the ones from the sources. e.g. given Args are {'label': {'label1=1','label2=1'}, 'image.name', {'ubuntu'}},
field is 'label' and sources are {'label1': '1', 'label2': '2'} it returns true.