Closed chris468 closed 1 year ago
Thank you very much for reporting this, and for the amazing bug report including a full set of scripts to reproduce the issue :)
Simplifying slightly, the fundamental problem was that the --promptBool
flag takes a map[string]string
value as an argument, but promptBoolOnce
was expecting a map[string]bool
value. So, promptBoolOnce
was silently ignoring the --promptBool
value. #2950 fixes this.
For the other aspects:
Your attempt to reproduce the problem with the test framework was really close. The things that stopped it from working are:
promptBoolOnce
function was falling back to reading a boolean value from the TTY, the test hangs instead. You can work around this by passing the --no-tty
flag to chezmoi (e.g. exec chezmoi init --no-tty
in the tests).promptBoolOnce
is the prompt, not the variable name. Compare https://github.com/twpayne/chezmoi/blob/4c2df35065ad1013695de90ea2c2efd16adf869e/pkg/cmd/testdata/scripts/init.txtar#L114 with https://github.com/twpayne/chezmoi/blob/8f219d8e00e403fad7fe463477ca38540530c31c/pkg/cmd/testdata/scripts/init.txtar#L114 to see the difference.The {{- "" -}}
is a hack to persuade text/template
to remove whitespace around template directives, while evaluating to nothing itself.
Thanks again!
I believe it is an issue w/ all of the
*Once
.promptBool
, etc. work.
It turns out that it was limited to promptBoolOnce
because of the map[string]bool
/ map[string]string
mismatch. promptIntOnce
uses a map[string]int
consistently, and promptStringOnce
uses a map[string]string
consistently. The tests seem to verify this.
Describe the bug
chezmoi init --promptString email="me@home.org"
prompts instead of using the email value from the command line.chezmoi execute-template --init --promptString email="me@home.org"
renders the prompt instead of the value from the command line.To reproduce
Follow the example from Create a config file on a new machine automatically on the User Guide Setup page, on a clean ubuntu 22.04 vm, script available here:
Output:
Expected behavior
The
execute-template
command should have outputThe
init
command should have used “me@home.org” for email without prompting.Output of command with the
--verbose
flagFrom above:
Output of
chezmoi doctor
Additional context
Discovered using
promptBoolOnce
, but used the example straight from the user guide for a reproducing case. I believe it is an issue w/ all of the*Once
.promptBool
, etc. work.Here is an attempt to reproduce in the tests. This makes the test hang, I suspect because it has prompted, but I don't know that testing framework.
I saw #2575, don’t think this is the same thing. I don’t understand what the
{{- “” -}}
at the end of the variables is for but it doesn’t seem to make a difference. I straight out of the setup guide, so if I’m missing something the doc may need to be updated.