-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathanalyze.go
60 lines (47 loc) · 1.03 KB
/
analyze.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
54
55
56
57
58
59
60
package k6exec
import (
"os"
"strings"
"github.com/grafana/k6deps"
)
func analyze(args []string, opts *Options) (k6deps.Dependencies, error) {
return k6deps.Analyze(newDepsOptions(args, opts))
}
func newDepsOptions(args []string, opts *Options) *k6deps.Options {
dopts := &k6deps.Options{
Env: opts.Env,
Manifest: opts.Manifest,
LookupEnv: opts.LookupEnv,
FindManifest: opts.FindManifest,
}
scriptname, hasScript := scriptArg(args)
if !hasScript {
return dopts
}
if _, err := os.Stat(scriptname); err != nil { //nolint:forbidigo
return dopts
}
if strings.HasSuffix(scriptname, ".tar") {
dopts.Archive.Name = scriptname
} else {
dopts.Script.Name = scriptname
}
return dopts
}
func scriptArg(args []string) (string, bool) {
if len(args) == 0 {
return "", false
}
cmd := args[0]
if cmd != "run" && cmd != "archive" && cmd != "inspect" {
return "", false
}
if len(args) == 1 {
return "", false
}
last := args[len(args)-1]
if last[0] == '-' {
return "", false
}
return last, true
}