twpayne / chezmoi

Manage your dotfiles across multiple diverse machines, securely.
https://www.chezmoi.io/
MIT License
12.85k stars 477 forks source link

promptBoolOnce always prompts on `chezmoi init` #2575

Closed gagbo closed 1 year ago

gagbo commented 1 year ago

Describe the bug

I have a list of "feature tags" that get prompted once during chezmoi init, 1 string and 2 booleans

Whenever I run chezmoi init additional times, I get prompted for the booleans again

To reproduce

Expected behavior

The boolean is not queried again.

Output of command with the --verbose flag

No output, but I do get the Does this machine synchronize email (y/n) ? prompt again (it cleans itself up once I answer)

$ chezmoi --verbose init
<Left empty on purpose>

Output of chezmoi doctor

```console $ chezmoi doctor RESULT CHECK MESSAGE ok version v2.27.1, commit b6039e787dfffe970fec4f9165ec9ebe1b3ceaa6, built at 2022-11-13T20:30:23Z, built by goreleaser ok latest-version v2.27.1 ok os-arch darwin/arm64 ok uname Darwin fp-gerry.lan 21.6.0 Darwin Kernel Version 21.6.0: Wed Aug 10 14:28:23 PDT 2022; root:xnu-8020.141.5~2/RELEASE_ARM64_T6000 arm64 ok go-version go1.19.3 (gc) ok executable ~/.local/bin/chezmoi ok upgrade-method replace-executable ok config-file ~/.config/chezmoi/chezmoi.toml, last modified 2022-11-17T10:10:13+01:00 ok source-dir ~/.local/share/chezmoi is a git working tree (clean) ok suspicious-entries no suspicious entries ok working-tree ~/.local/share/chezmoi is a git working tree (clean) ok dest-dir ~ is a directory ok umask 022 ok cd-command found /bin/zsh ok cd-args /bin/zsh info diff-command not set ok edit-command found /opt/homebrew/bin/nvim ok edit-args /opt/homebrew/bin/nvim ok git-command found /usr/bin/git, version 2.37.0 ok merge-command found /usr/bin/vimdiff ok shell-command found /bin/zsh ok shell-args /bin/zsh ok age-command found /opt/homebrew/bin/age, version 1.0.0 ok gpg-command found /opt/homebrew/bin/gpg, version 2.3.8 ok pinentry-command found /opt/homebrew/bin/pinentry-mac, version 1.1.1 info 1password-command op not found in $PATH info bitwarden-command bw not found in $PATH info gopass-command gopass not found in $PATH info keepassxc-command keepassxc-cli not found in $PATH info keepassxc-db not set info keeper-command keeper not found in $PATH info lastpass-command lpass not found in $PATH info pass-command pass not found in $PATH info passhole-command ph not found in $PATH info vault-command vault not found in $PATH info secret-command not set ```

Additional context

In this case I run on Apple Silicon M1, but I also have this issue on my Fedora machine

halostatue commented 1 year ago

I believe that you want to change this:

{{/* boolean feature tags */}}
{{- $email := promptStringOnce . "email" "What is the email address ?" -}}
{{- $handleEmail := promptBoolOnce . "flags.email" "Does this machine synchronize email (y/n) ?" -}}
{{- $useFish := promptBoolOnce . "flags.fish" "Does this machine use Fish as a shell (y/n) ?" -}}
{{- "" -}}

[data]
    email = {{ $email | quote }}
    osid = {{ $osid | quote }}
    chassisType = {{ $chassisType | quote }}
    flags.email = {{ $handleEmail }}
    flags.fish = {{ $useFish }}

Or rename flags.email to handleEmail and flags.fish to useFish.

I could be wrong.

gagbo commented 1 year ago

Oh right, I thought from reading the doc that the "path" in prompt*Once was mentioning variable names, not path in chezmoi data.

Changing the path to flags.foo works indeed thanks