Fix: trim quot char for velaql output (#4267)

Signed-off-by: Jianbo Sun <jianbo.sjb@alibaba-inc.com>
This commit is contained in:
Jianbo Sun
2022-06-27 16:48:31 +08:00
committed by GitHub
parent 8b441b6579
commit 0e98959d61
2 changed files with 8 additions and 4 deletions
+7 -3
View File
@@ -21,6 +21,7 @@ import (
"context"
"encoding/json"
"fmt"
"strings"
"github.com/spf13/cobra"
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -47,7 +48,10 @@ func NewQlCommand(c common.Args, order string, ioStreams util.IOStreams) *cobra.
cmd := &cobra.Command{
Use: "ql",
Short: "Show result of executing velaQL.",
Long: "Show result of executing velaQL.",
Long: `Show result of executing velaQL, use it like:
vela ql --query "<inner-view-name>{<param1>=<value1>,<param2>=<value2>}
vela ql --file=./ql.cue
`,
Example: `Users can query with a query statement:
vela ql --query "<inner-view-name>{<param1>=<value1>,<param2>=<value2>}"
They can also query by a ql file:
@@ -133,11 +137,11 @@ func print(queryValue *value.Value, cmd *cobra.Command) error {
return err
}
var out bytes.Buffer
err = json.Indent(&out, response, "", " ")
err = json.Indent(&out, response, "", " ")
if err != nil {
return err
}
cmd.Printf("%s\n", out.String())
cmd.Println(strings.Trim(strings.TrimSpace(out.String()), "\""))
return nil
}
+1 -1
View File
@@ -76,7 +76,7 @@ export: "status"
var buff = bytes.NewBufferString("")
cmd.SetOut(buff)
Expect(queryFromView(context.TODO(), k8sClient, arg, name, cmd)).Should(BeNil())
Expect(buff.String()).Should(ContainSubstring(`my-value`))
Expect(strings.TrimSpace(buff.String())).Should(BeEquivalentTo("my-value"))
})
})