1
0
mirror of https://github.com/MontFerret/ferret.git synced 2024-12-16 11:37:36 +02:00
ferret/cmd/cli/app/exec.go

50 lines
766 B
Go
Raw Normal View History

2018-09-18 22:42:38 +02:00
package app
import (
"context"
"fmt"
"github.com/MontFerret/ferret/pkg/compiler"
"github.com/MontFerret/ferret/pkg/runtime"
"io/ioutil"
"os"
)
func ExecFile(pathToFile string, opts Options) {
2018-09-18 22:42:38 +02:00
query, err := ioutil.ReadFile(pathToFile)
if err != nil {
fmt.Println(err)
os.Exit(1)
return
}
Exec(string(query), opts)
}
func Exec(query string, opts Options) {
2018-09-18 22:42:38 +02:00
ferret := compiler.New()
prog, err := ferret.Compile(query)
2018-09-18 22:42:38 +02:00
if err != nil {
fmt.Println("Failed to compile the query")
fmt.Println(err)
os.Exit(1)
return
}
out, err := prog.Run(
context.Background(),
runtime.WithBrowser(opts.Cdp),
)
2018-09-18 22:42:38 +02:00
if err != nil {
fmt.Println("Failed to execute the query")
fmt.Println(err)
os.Exit(1)
return
}
fmt.Println(string(out))
}