forked from miaokobot/miaospeed
-
Notifications
You must be signed in to change notification settings - Fork 9
/
cli_script.go
53 lines (40 loc) · 1.22 KB
/
cli_script.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
49
50
51
52
53
package main
import (
"flag"
"fmt"
"os"
"github.com/airportr/miaospeed/interfaces"
"github.com/airportr/miaospeed/service/macros/script"
"github.com/airportr/miaospeed/utils"
"github.com/airportr/miaospeed/vendors"
)
type ScriptTestCliParams struct {
ScriptName string
}
func InitConfigScriptTest() *ScriptTestCliParams {
stcp := &ScriptTestCliParams{}
sflag := flag.NewFlagSet(cmdName+" script", flag.ExitOnError)
sflag.StringVar(&stcp.ScriptName, "file", "", "specify a script file to perform a test.")
parseFlag(sflag)
return stcp
}
func RunCliScriptTest() {
stcp := InitConfigScriptTest()
if stcp.ScriptName == "" {
utils.DErrorf("Script Test | File name cannot be empty.")
os.Exit(1)
}
fileContent, err := os.ReadFile(stcp.ScriptName)
if err != nil {
utils.DErrorf("Script Test | Cannot read the file, path=%s", stcp.ScriptName)
os.Exit(1)
}
utils.VerboseLevel = utils.LTInfo
utils.DWarnf("MiaoSpeed speedtesting client %s", utils.VERSION)
vendor := vendors.Find(interfaces.VendorLocal)
utils.DInfof("Script Test | Using vendor %s", vendor.Type())
scriptResult := script.ExecScript(vendor, &interfaces.Script{
Content: string(fileContent),
})
fmt.Println("\n" + utils.ToJSON(scriptResult))
}