Fix: support stdin and url for vela ql (#4274)

Signed-off-by: Jianbo Sun <jianbo.sjb@alibaba-inc.com>
This commit is contained in:
Jianbo Sun
2022-06-29 14:50:24 +08:00
committed by GitHub
parent 370940070b
commit 71df27a8c3
2 changed files with 5 additions and 6 deletions
+2 -3
View File
@@ -17,8 +17,6 @@
package velaql
import (
"io/ioutil"
"path/filepath"
"regexp"
"strconv"
"strings"
@@ -26,6 +24,7 @@ import (
"github.com/pkg/errors"
"github.com/oam-dev/kubevela/pkg/cue/model/value"
"github.com/oam-dev/kubevela/references/common"
)
// QueryView contains query data
@@ -99,7 +98,7 @@ func ParseVelaQL(ql string) (QueryView, error) {
// ParseVelaQLFromPath will parse a velaQL file path to QueryView
func ParseVelaQLFromPath(velaQLViewPath string) (*QueryView, error) {
body, err := ioutil.ReadFile(filepath.Clean(velaQLViewPath))
body, err := common.ReadRemoteOrLocalPath(velaQLViewPath)
if err != nil {
return nil, errors.Errorf("read view file from %s: %v", velaQLViewPath, err)
}
+3 -3
View File
@@ -50,12 +50,12 @@ func NewQlCommand(c common.Args, order string, ioStreams util.IOStreams) *cobra.
Short: "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
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:
vela ql --file=./ql.cue
vela ql --file ./ql.cue
Example content of ql.cue:
---
@@ -99,7 +99,7 @@ export: "status"
types.TagCommandType: types.TypeApp,
},
}
cmd.Flags().StringVarP(&cueFile, "file", "f", "", "The CUE file path for VelaQL.")
cmd.Flags().StringVarP(&cueFile, "file", "f", "", "The CUE file path for VelaQL, it could be a remote url.")
cmd.Flags().StringVarP(&querySts, "query", "q", "", "The query statement for VelaQL.")
cmd.SetOut(ioStreams.Out)
return cmd