Skip to content

Commit

Permalink
Fix raw output having quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Olenik committed Feb 28, 2019
1 parent 5eac579 commit 391bc0b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
3 changes: 2 additions & 1 deletion cmd/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ func getOutput(obj interface{}, raw bool) (string, error) {
if isArray {
for _, item := range arr {
// Simple output, uses built-in %v, most useful for simple types.
result += fmt.Sprintf("%v", item) + " "
result += strings.Trim(fmt.Sprintf("%v", item), `"`) + " "
}
result = strings.TrimRight(result, " ")
return result, nil
}
return strings.Trim(fmt.Sprintf("%v", obj), `"`), nil
}
jsonBody, err := json.Marshal(obj)
if err != nil {
Expand Down
8 changes: 6 additions & 2 deletions cmd/get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ var getTests = []struct {
{`a = 12`, ``, Args{"get", "a[]"}, "wrong type"},
{`a = [12]`, `[12]`, Args{"get", "a[]"}, ""},
{`a = [12]`, `12`, Args{"get", "a[0]"}, ""},
{`a = ["a"]`, `"a"`, Args{"get", "a[0]"}, ""},
{`a = ["a"]`, `a`, Args{"get", "-r", "a[0]"}, ""},
{`a = ["a", "b"]`, `["a","b"]`, Args{"get", "a[]"}, ""},
{`a = ["a", "b"]`, `a b`, Args{"get", "-r", "a[]"}, ""},
{`a = [1, 2, 3]`, `[1,2,3]`, Args{"get", "a[]"}, ""},
{`a = [1, 2, 3]`, `1`, Args{"get", "a[0]"}, ""},
{`a = [1, 2, 3]`, `2`, Args{"get", "a[1]"}, ""},
Expand All @@ -32,8 +36,8 @@ var getTests = []struct {
{`a = []`, `[]`, Args{"get", "a[]"}, ""},
{`a = []`, ``, Args{"get", "a"}, "wrong type"},
{`a { b = "2" }`, `"2"`, Args{"get", "a.b"}, ""},
{`a { b = "2" }`, `"2"`, Args{"get", "-r", "a.b"}, ""},
{`a { b = "2a" }`, `"2a"`, Args{"get", "-r", "a.b"}, ""},
{`a { b = "2" }`, `2`, Args{"get", "-r", "a.b"}, ""},
{`a { b = "2a" }`, `2a`, Args{"get", "-r", "a.b"}, ""},
{`a "b" { c = [1] }`, `[1]`, Args{"get", "a.b.c[]"}, ""},
}

Expand Down

0 comments on commit 391bc0b

Please sign in to comment.