v1.0.1 Latest Latest

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

Go to latest
Published: Dec 9, 2015 License: Apache-2.0 Imports: 4 Imported by: 0



Package filters provides helper function to parse and handle command line filter, used for example in docker ps or docker images commands.



This section is empty.


View Source
var ErrBadFormat = errors.New("bad format of filter (expected name=value)")

ErrBadFormat is an error returned in case of bad format for a filter.


func ToParam

func ToParam(a Args) (string, error)

ToParam packs the Args into an string for easy transport from client to server.


type Args

type Args map[string][]string

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 '' the args will be {'label': {'label1=1','label2=2'}, '', {'ubuntu'}}

func FromParam

func FromParam(p string) (Args, error)

FromParam unpacks the filter Args.

func ParseFlag

func ParseFlag(arg string, prev Args) (Args, error)

ParseFlag parses the argument to the filter flag. Like

`docker ps -f 'created=today' -f '*'`

If prev map is provided, then it is appended to, and returned. By default a new map is created.

func (Args) Match

func (filters Args) Match(field, source string) bool

Match returns true if the values for the specified field matches the source string e.g. given Args are {'label': {'label1=1','label2=1'}, '', {'ubuntu'}},

field is '' and source is 'ubuntu'
it returns true.

func (Args) MatchKVList added in v0.3.0

func (filters Args) MatchKVList(field string, sources map[string]string) bool

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'}, '', {'ubuntu'}},

field is 'label' and sources are {'label':{'label1=1','label2=2','label3=3'}}
it returns true.

Jump to

Keyboard shortcuts

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