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 Nov 6, 2019
1 parent 04e6f79 commit 97fdd73
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 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,20 @@ 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" or "base"
base: pure Golang JS VM supporting ES5.1+
extended: base + Babel with ES2015 preset + core.js v2,
slower and memory consuming but with greater JS support
`)
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 +90,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 97fdd73

Please sign in to comment.