|
@@ -2,46 +2,51 @@ package filters
|
|
|
|
|
|
import (
|
|
import (
|
|
"errors"
|
|
"errors"
|
|
|
|
+ "github.com/dotcloud/docker/pkg/beam/data"
|
|
"strings"
|
|
"strings"
|
|
)
|
|
)
|
|
|
|
|
|
|
|
+type Args map[string][]string
|
|
|
|
+
|
|
/*
|
|
/*
|
|
Parse the argument to the filter flag. Like
|
|
Parse the argument to the filter flag. Like
|
|
|
|
|
|
- `docker ps -f 'created=today;image.name=ubuntu*'`
|
|
|
|
-
|
|
|
|
-Filters delimited by ';', and expected to be 'name=value'
|
|
|
|
|
|
+ `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
|
|
If prev map is provided, then it is appended to, and returned. By default a new
|
|
map is created.
|
|
map is created.
|
|
*/
|
|
*/
|
|
-func ParseFlag(arg string, prev map[string]string) (map[string]string, error) {
|
|
|
|
- var filters map[string]string
|
|
|
|
- if prev != nil {
|
|
|
|
- filters = prev
|
|
|
|
- } else {
|
|
|
|
- filters = map[string]string{}
|
|
|
|
|
|
+func ParseFlag(arg string, prev Args) (Args, error) {
|
|
|
|
+ var filters Args = prev
|
|
|
|
+ if prev == nil {
|
|
|
|
+ filters = Args{}
|
|
}
|
|
}
|
|
if len(arg) == 0 {
|
|
if len(arg) == 0 {
|
|
return filters, nil
|
|
return filters, nil
|
|
}
|
|
}
|
|
|
|
|
|
- for _, chunk := range strings.Split(arg, ";") {
|
|
|
|
- if !strings.Contains(chunk, "=") {
|
|
|
|
- return filters, ErrorBadFormat
|
|
|
|
- }
|
|
|
|
- f := strings.SplitN(chunk, "=", 2)
|
|
|
|
- filters[f[0]] = f[1]
|
|
|
|
|
|
+ if !strings.Contains(arg, "=") {
|
|
|
|
+ return filters, ErrorBadFormat
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ f := strings.SplitN(arg, "=", 2)
|
|
|
|
+ filters[f[0]] = append(filters[f[0]], f[1])
|
|
|
|
+
|
|
return filters, nil
|
|
return filters, nil
|
|
}
|
|
}
|
|
|
|
|
|
var ErrorBadFormat = errors.New("bad format of filter (expected name=value)")
|
|
var ErrorBadFormat = errors.New("bad format of filter (expected name=value)")
|
|
|
|
|
|
-func ToParam(f map[string]string) string {
|
|
|
|
- fs := []string{}
|
|
|
|
- for k, v := range f {
|
|
|
|
- fs = append(fs, k+"="+v)
|
|
|
|
- }
|
|
|
|
- return strings.Join(fs, ";")
|
|
|
|
|
|
+/*
|
|
|
|
+packs the Args into an string for easy transport from client to server
|
|
|
|
+*/
|
|
|
|
+func ToParam(a Args) string {
|
|
|
|
+ return data.Encode(a)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/*
|
|
|
|
+unpacks the filter Args
|
|
|
|
+*/
|
|
|
|
+func FromParam(p string) (Args, error) {
|
|
|
|
+ return data.Decode(p)
|
|
}
|
|
}
|