Skip to content

Commit

Permalink
util: Always override config file flags from the command line
Browse files Browse the repository at this point in the history
Currently we check whether a flag's current value differs from its
default in order to skip the value from the config file. That works
in most cases, but as a result it is not possible to override a value
from the config by explicitly passing the default value:

  [mr_show]
  comments = true

  $ lab mr show --comments=false

Fix this by checking the flag's Changed property instead.
  • Loading branch information
fmuellner authored and prarit committed Dec 20, 2020
1 parent bf71f13 commit c743a49
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
27 changes: 27 additions & 0 deletions cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,3 +380,30 @@ func Test_flag_config_TF(t *testing.T) {
// both configs set to true, comments should be output
require.Contains(t, string(b), `commented at`)
}

// flag (explicitly) unset, config true == no comments
func Test_flag_config_FT(t *testing.T) {
repo := copyTestRepo(t)

err := setConfigValues(repo, "true", "true")
if err != nil {
t.Skip(err)
}
os.Remove(repo + "/lab.toml")

cmd := exec.Command(labBinaryPath, "mr", "show", "1", "--comments=false")
cmd.Dir = repo

b, err := cmd.CombinedOutput()
if err != nil {
t.Log(string(b))
t.Error(err)
}

out := string(b)
out = stripansi.Strip(out)

os.Remove("/home/travis/.config/lab/lab.toml")
// configs overridden on the command line, comments should not be output
require.NotContains(t, string(b), `commented at`)
}
2 changes: 1 addition & 1 deletion cmd/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func flagConfig(fs *flag.FlagSet) {
}

// if set, always use the command line option (flag) value
if f.Value.String() != f.DefValue {
if f.Changed {
return
}
// o/w use the value in the configfile
Expand Down

0 comments on commit c743a49

Please sign in to comment.