Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

skip any parsing of config files if the -v flag is provided #446

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 25 additions & 24 deletions lib/param_parsing/parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,32 +52,33 @@ func GetParameters() Params {
// Parse the command line parameters to fetch stuff like chdir
getopt.Parse()

oldLogLevel := params.LogLevel
logger = lib.InitLogger(params.LogLevel)
var err error
// Read configuration files
if tomlFileExists(params) {
params, err = getParamsTOML(params)
} else if tfSwitchFileExists(params) {
params, err = GetParamsFromTfSwitch(params)
} else if terraformVersionFileExists(params) {
params, err = GetParamsFromTerraformVersion(params)
} else if isTerraformModule(params) {
params, err = GetVersionFromVersionsTF(params)
} else if terraGruntFileExists(params) {
params, err = GetVersionFromTerragrunt(params)
} else {
params = GetParamsFromEnvironment(params)
}
if err != nil {
logger.Fatalf("Error parsing configuration file: %q", err)
}

// Logger config was changed by the config files. Reinitialise.
if params.LogLevel != oldLogLevel {
if !params.VersionFlag {
MatrixCrawler marked this conversation as resolved.
Show resolved Hide resolved
oldLogLevel := params.LogLevel
logger = lib.InitLogger(params.LogLevel)
}
var err error
// Read configuration files
if tomlFileExists(params) {
params, err = getParamsTOML(params)
} else if tfSwitchFileExists(params) {
params, err = GetParamsFromTfSwitch(params)
} else if terraformVersionFileExists(params) {
params, err = GetParamsFromTerraformVersion(params)
} else if isTerraformModule(params) {
params, err = GetVersionFromVersionsTF(params)
} else if terraGruntFileExists(params) {
params, err = GetVersionFromTerragrunt(params)
} else {
params = GetParamsFromEnvironment(params)
}
if err != nil {
logger.Fatalf("Error parsing configuration file: %q", err)
}

// Logger config was changed by the config files. Reinitialise.
if params.LogLevel != oldLogLevel {
logger = lib.InitLogger(params.LogLevel)
}
}
// Parse again to overwrite anything that might by defined on the cli AND in any config file (CLI always wins)
getopt.Parse()
args := getopt.Args()
Expand Down