|
1 | 1 | package k6exec
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "log/slog" |
4 | 5 | "os"
|
5 | 6 | "strings"
|
6 | 7 |
|
7 | 8 | "github.com/grafana/k6deps"
|
8 | 9 | )
|
9 | 10 |
|
10 | 11 | func analyze(args []string, opts *Options) (k6deps.Dependencies, error) {
|
11 |
| - return k6deps.Analyze(newDepsOptions(args, opts)) |
| 12 | + depsOpts := newDepsOptions(args, opts) |
| 13 | + |
| 14 | + // we call Analyze before logging because it will return the name of the manifest, in any |
| 15 | + deps, err := k6deps.Analyze(depsOpts) |
| 16 | + |
| 17 | + slog.Debug("analyzing sources", depsOptsAttrs(depsOpts)...) |
| 18 | + |
| 19 | + if err == nil && len(deps) > 0 { |
| 20 | + slog.Debug("found dependencies", "deps", deps.String()) |
| 21 | + } |
| 22 | + |
| 23 | + return deps, err |
12 | 24 | }
|
13 | 25 |
|
14 | 26 | func newDepsOptions(args []string, opts *Options) *k6deps.Options {
|
@@ -58,3 +70,26 @@ func scriptArg(args []string) (string, bool) {
|
58 | 70 |
|
59 | 71 | return last, true
|
60 | 72 | }
|
| 73 | + |
| 74 | +func depsOptsAttrs(opts *k6deps.Options) []any { |
| 75 | + attrs := []any{} |
| 76 | + |
| 77 | + if opts.Manifest.Name != "" { |
| 78 | + attrs = append(attrs, "Manifest", opts.Manifest.Name) |
| 79 | + } |
| 80 | + |
| 81 | + if opts.Archive.Name != "" { |
| 82 | + attrs = append(attrs, "Archive", opts.Archive.Name) |
| 83 | + } |
| 84 | + |
| 85 | + // ignore script if archive is present |
| 86 | + if opts.Archive.Name == "" && opts.Script.Name != "" { |
| 87 | + attrs = append(attrs, "Script", opts.Script.Name) |
| 88 | + } |
| 89 | + |
| 90 | + if opts.Env.Name != "" { |
| 91 | + attrs = append(attrs, "Env", opts.Env.Name) |
| 92 | + } |
| 93 | + |
| 94 | + return attrs |
| 95 | +} |
0 commit comments