This repository has been archived by the owner on Sep 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
client: Fix param parsing when spaces are used
Up until now we only recognized dynamic parameters passed in the following format: $ mistry -- --foo=bar --a=b --b=c With this patch, the above can also be written as: the above: $ mistry -- --foo bar --a b --b c Fixes #23
- Loading branch information
Showing
2 changed files
with
67 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package main | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/urfave/cli" | ||
) | ||
|
||
func TestParseDynamicArgs(t *testing.T) { | ||
cases := []struct { | ||
In cli.Args | ||
Expected map[string]string | ||
}{ | ||
{cli.Args{"--a", "b", "c=d", "e=f", "--g", "h"}, | ||
map[string]string{"a": "b", "c": "d", "e": "f", "g": "h"}}, | ||
|
||
{cli.Args{"a=b", "--@c", "d", "e=f", "--g", "h"}, | ||
map[string]string{"a": "b", "@c": "d", "e": "f", "g": "h"}}, | ||
|
||
{cli.Args{"a=b", "--c", "d"}, | ||
map[string]string{"a": "b", "c": "d"}}, | ||
|
||
{cli.Args{"--a", "b", "@c=d"}, | ||
map[string]string{"a": "b", "@c": "d"}}, | ||
|
||
{cli.Args{"a=b", "c=d"}, | ||
map[string]string{"a": "b", "c": "d"}}, | ||
|
||
{cli.Args{"a", "b", "--c", "d"}, | ||
map[string]string{"a": "b", "c": "d"}}, | ||
|
||
{cli.Args{"--a", "b"}, map[string]string{"a": "b"}}, | ||
{cli.Args{"a=b"}, map[string]string{"a": "b"}}, | ||
} | ||
|
||
for _, c := range cases { | ||
actual := parseDynamicArgs(c.In) | ||
|
||
if !reflect.DeepEqual(actual, c.Expected) { | ||
t.Errorf("expected %v, got %v", c.Expected, actual) | ||
} | ||
} | ||
} |