|
@@ -8,14 +8,12 @@ import (
|
|
|
|
|
|
type Args map[string][]string
|
|
|
|
|
|
-/*
|
|
|
-Parse 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.
|
|
|
-*/
|
|
|
+// Parse 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 ParseFlag(arg string, prev Args) (Args, error) {
|
|
|
var filters Args = prev
|
|
|
if prev == nil {
|
|
@@ -37,10 +35,13 @@ func ParseFlag(arg string, prev Args) (Args, error) {
|
|
|
|
|
|
var ErrorBadFormat = errors.New("bad format of filter (expected name=value)")
|
|
|
|
|
|
-/*
|
|
|
-packs the Args into an string for easy transport from client to server
|
|
|
-*/
|
|
|
+// packs the Args into an string for easy transport from client to server
|
|
|
func ToParam(a Args) (string, error) {
|
|
|
+ // this way we don't URL encode {}, just empty space
|
|
|
+ if len(a) == 0 {
|
|
|
+ return "", nil
|
|
|
+ }
|
|
|
+
|
|
|
buf, err := json.Marshal(a)
|
|
|
if err != nil {
|
|
|
return "", err
|
|
@@ -48,11 +49,12 @@ func ToParam(a Args) (string, error) {
|
|
|
return string(buf), nil
|
|
|
}
|
|
|
|
|
|
-/*
|
|
|
-unpacks the filter Args
|
|
|
-*/
|
|
|
+// unpacks the filter Args
|
|
|
func FromParam(p string) (Args, error) {
|
|
|
args := Args{}
|
|
|
+ if len(p) == 0 {
|
|
|
+ return args, nil
|
|
|
+ }
|
|
|
err := json.Unmarshal([]byte(p), &args)
|
|
|
if err != nil {
|
|
|
return nil, err
|