Skip to content

Commit

Permalink
feat(cmd): expose compatibility mode option to CLI
Browse files Browse the repository at this point in the history
Closes #1049
  • Loading branch information
Ivan Mirić committed Oct 25, 2019
1 parent c463026 commit 1e1112c
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions cmd/runtime_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/loadimpact/k6/lib"
"github.com/pkg/errors"
"github.com/spf13/pflag"
"gopkg.in/guregu/null.v3"
)

var userEnvVarName = regexp.MustCompile(`^[a-zA-Z_][a-zA-Z0-9_]*$`)
Expand All @@ -52,13 +53,16 @@ func runtimeOptionFlagSet(includeSysEnv bool) *pflag.FlagSet {
flags := pflag.NewFlagSet("", 0)
flags.SortFlags = false
flags.Bool("include-system-env-vars", includeSysEnv, "pass the real system environment variables to the runtime")
flags.String("compatibility-mode", "extended",
`JavaScript compiler compatibility mode, "extended" (ES6+) or "base" (ES5.1+)`)
flags.StringArrayP("env", "e", nil, "add/override environment variable with `VAR=value`")
return flags
}

func getRuntimeOptions(flags *pflag.FlagSet) (lib.RuntimeOptions, error) {
opts := lib.RuntimeOptions{
IncludeSystemEnvVars: getNullBool(flags, "include-system-env-vars"),
CompatibilityMode: getNullString(flags, "compatibility-mode"),
Env: make(map[string]string),
}

Expand All @@ -82,5 +86,11 @@ func getRuntimeOptions(flags *pflag.FlagSet) (lib.RuntimeOptions, error) {
opts.Env[k] = v
}

// Fallback to env
compatMode := opts.Env["K6_COMPATIBILITY_MODE"]
if !opts.CompatibilityMode.Valid && compatMode != "" {
opts.CompatibilityMode = null.StringFrom(compatMode)
}

return opts, nil
}

0 comments on commit 1e1112c

Please sign in to comment.