aboutsummaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
Diffstat (limited to 'commands')
-rw-r--r--commands/ls.go23
-rw-r--r--commands/ls_test.go43
2 files changed, 59 insertions, 7 deletions
diff --git a/commands/ls.go b/commands/ls.go
index 909e25a8..da5ea8ce 100644
--- a/commands/ls.go
+++ b/commands/ls.go
@@ -103,13 +103,9 @@ func runLs(env *Env, opts lsOptions, args []string) error {
var err error
if len(args) >= 1 {
- // either the shell or cobra remove the quotes, we need them back for the parsing
- for i, arg := range args {
- if strings.Contains(arg, " ") {
- args[i] = fmt.Sprintf("\"%s\"", arg)
- }
- }
- assembled := strings.Join(args, " ")
+ // either the shell or cobra remove the quotes, we need them back for the query parsing
+ assembled := repairQuery(args)
+
q, err = query.Parse(assembled)
if err != nil {
return err
@@ -153,6 +149,19 @@ func runLs(env *Env, opts lsOptions, args []string) error {
}
}
+func repairQuery(args []string) string {
+ for i, arg := range args {
+ split := strings.Split(arg, ":")
+ for j, s := range split {
+ if strings.Contains(s, " ") {
+ split[j] = fmt.Sprintf("\"%s\"", s)
+ }
+ }
+ args[i] = strings.Join(split, ":")
+ }
+ return strings.Join(args, " ")
+}
+
type JSONBugExcerpt struct {
Id string `json:"id"`
HumanId string `json:"human_id"`
diff --git a/commands/ls_test.go b/commands/ls_test.go
new file mode 100644
index 00000000..aff94e03
--- /dev/null
+++ b/commands/ls_test.go
@@ -0,0 +1,43 @@
+package commands
+
+import (
+ "testing"
+
+ "github.com/stretchr/testify/require"
+)
+
+func Test_repairQuery(t *testing.T) {
+ cases := []struct {
+ args []string
+ output string
+ }{
+ {
+ []string{""},
+ "",
+ },
+ {
+ []string{"foo"},
+ "foo",
+ },
+ {
+ []string{"foo", "bar"},
+ "foo bar",
+ },
+ {
+ []string{"foo bar", "baz"},
+ "\"foo bar\" baz",
+ },
+ {
+ []string{"foo:bar", "baz"},
+ "foo:bar baz",
+ },
+ {
+ []string{"foo:bar boo", "baz"},
+ "foo:\"bar boo\" baz",
+ },
+ }
+
+ for _, tc := range cases {
+ require.Equal(t, tc.output, repairQuery(tc.args))
+ }
+}