forked from sensorbee/sensorbee
/
cmd_file_load.go
48 lines (40 loc) · 993 Bytes
/
cmd_file_load.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package shell
import (
"fmt"
"gopkg.in/sensorbee/sensorbee.v0/client"
"io/ioutil"
"strings"
)
// NewFileLoadCommands returns command list to load BQL file.
func NewFileLoadCommands() []Command {
return []Command{
&fileLoadCmd{},
}
}
type fileLoadCmd struct {
queries string
filePath string
}
func (f *fileLoadCmd) Init() error {
return nil
}
func (f *fileLoadCmd) Name() []string {
return []string{"file"}
}
func (f *fileLoadCmd) Input(input string) (cmdInputStatusType, error) {
inputs := strings.Split(input, " ")
if len(inputs) != 2 {
return invalidCMD, fmt.Errorf("cannot read file name")
}
f.filePath = inputs[1]
// file load
queries, err := ioutil.ReadFile(f.filePath)
if err != nil {
return invalidCMD, fmt.Errorf("cannot read queries from file: %v", f.filePath)
}
f.queries = string(queries)
return preparedCMD, nil
}
func (f *fileLoadCmd) Eval(requester *client.Requester) {
fmt.Println("Eval() not implemented for fileLoadCmd, use App instead")
}