forked from ooni/probe-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
javascript.go
40 lines (34 loc) · 1.29 KB
/
javascript.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
package main
import (
"path/filepath"
"github.com/apex/log"
"github.com/ooni/probe-cli/v3/internal/runtimex"
"github.com/ooni/probe-cli/v3/internal/x/dsljavascript"
"github.com/spf13/cobra"
)
// registerJavaScript registers the javascript subcommand
func registerJavaScript(rootCmd *cobra.Command, _ *Options) {
subCmd := &cobra.Command{
Use: "javascript",
Short: "Very experimental command to run JavaScript snippets",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
runtimex.Assert(len(args) == 1, "expected exactly one argument")
javaScriptMain(args[0])
},
}
rootCmd.AddCommand(subCmd)
}
func javaScriptMain(scriptPath string) {
// TODO(bassosimone): for an initial prototype, using a local directory is
// good, but, if we make this more production ready, we probably need to define
// a specific location under the $OONI_HOME.
config := &dsljavascript.VMConfig{
Logger: log.Log,
ScriptBaseDir: filepath.Join(".", "./javascript"),
}
log.Warnf("The javascript subcommand is highly experimental and may be removed")
log.Warnf("or heavily modified without prior notice. For more information, for now")
log.Warnf("see https://github.com/bassosimone/2023-12-09-ooni-javascript.")
runtimex.Try0(dsljavascript.RunScript(config, scriptPath))
}