MCPcopy
hub / github.com/grafana/k6 / persistentPreRunE

Method persistentPreRunE

internal/cmd/root.go:140–169  ·  view source on GitHub ↗
(cmd *cobra.Command, _ []string)

Source from the content-addressed store, hash-verified

138}
139
140func (c *rootCommand) persistentPreRunE(cmd *cobra.Command, _ []string) error {
141 // The 'cloud' secret source is managed automatically and is not a valid value for
142 // --secret-source. Reject it here, before auto-injection, so the check only sees
143 // user-provided values. The logger is not yet configured at this point, so write
144 // the error directly to gs.Stderr and return errAlreadyReported to suppress the
145 // duplicate log entry that execute() would otherwise emit.
146 if err := validateNoCloudSecretSource(c.globalState.Flags.SecretSource); err != nil {
147 _, _ = fmt.Fprintln(c.globalState.Stderr, err.Error())
148 return errext.WithExitCodeIfNone(errAlreadyReported, exitcodes.InvalidConfig)
149 }
150
151 // For 'k6 cloud run --local-execution', automatically register the cloud secret source
152 // so scripts can call secrets.get() without any extra flags.
153 // This must happen before setupLoggers, which calls createSecretSources internally.
154 if isCloudRunWithLocalExecution(cmd) {
155 f := cmd.Flag("no-cloud-secrets")
156 if f == nil || f.Value.String() != "true" {
157 c.globalState.Flags.SecretSource = append(c.globalState.Flags.SecretSource, "cloud")
158 }
159 }
160
161 err := c.setupLoggers(c.stopLoggersCh)
162 if err != nil {
163 return err
164 }
165
166 c.globalState.Logger.Debugf("k6 version: v%s", fullVersion())
167
168 return nil
169}
170
171func (c *rootCommand) execute() {
172 ctx, cancel := context.WithCancel(c.globalState.Ctx)

Callers

nothing calls this directly

Calls 8

setupLoggersMethod · 0.95
WithExitCodeIfNoneFunction · 0.92
fullVersionFunction · 0.85
DebugfMethod · 0.80
ErrorMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected