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"
|
|
|
|
)
|
|
|
|
|
2018-09-23 08:05:05 +02:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2018-09-23 08:05:05 +02:00
|
|
|
Exec(string(query), opts)
|
|
|
|
}
|
|
|
|
|
|
|
|
func Exec(query string, opts Options) {
|
2018-09-18 22:42:38 +02:00
|
|
|
ferret := compiler.New()
|
|
|
|
|
2018-09-23 08:05:05 +02:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2018-09-23 08:05:05 +02:00
|
|
|
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))
|
|
|
|
}
|