twpayne / chezmoi

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

`—prompt*` not working #3298

Closed zydou closed 1 year ago

zydou commented 1 year ago

Describe the bug

https://github.com/twpayne/chezmoi/issues/2945 still exists.

To reproduce

create the following test.sh script

#!/usr/bin/env bash

mkdir -p $HOME/.local/share/chezmoi

cat > $HOME/.local/share/chezmoi/.chezmoi.toml.tmpl <<EOF
{{- \$testString := promptString "test promptString" -}}
{{- \$testStringOnce := promptStringOnce . "testStringOnce" "test promptStringOnce" -}}

[data]
    testString = {{ \$testString | quote }}
    testStringOnce = {{ \$testStringOnce | quote }}
EOF

echo "$HOME/.local/share/chezmoi/.chezmoi.toml.tmpl contents:"
cat $HOME/.local/share/chezmoi/.chezmoi.toml.tmpl
echo

sh -c "$(curl -fsLS get.chezmoi.io)" -- -b $HOME/bin -t latest

$HOME/bin/chezmoi init --promptString testString=testString,testStringOnce=testStringOnce
cat $HOME/.config/chezmoi/chezmoi.toml

test in docker:

$ docker run --rm -it -v ./test.sh:/test.sh buildpack-deps:jammy /test.sh

/root/.local/share/chezmoi/.chezmoi.toml.tmpl contents:
{{- $testString := promptString "test promptString" -}}
{{- $testStringOnce := promptStringOnce . "testStringOnce" "test promptStringOnce" -}}

[data]
    testString = {{ $testString | quote }}
    testStringOnce = {{ $testStringOnce | quote }}

info found version 2.40.3 for latest/linux/amd64
info installed /root/bin/chezmoi
test promptString? string

Expected behavior

[data]
    testString = "testString"
    testStringOnce = "testStringOnce"

Output of chezmoi doctor

```console $ chezmoi doctor RESULT CHECK MESSAGE ok version v2.40.3, commit 294c2c8bea1d9fda0b14bd029774dc96e066c0cd, built at 2023-10-12T21:11:59Z, built by goreleaser ok latest-version v2.40.3 ok os-arch linux/amd64 (Ubuntu 22.04.3 LTS (Jammy Jellyfish)) ok uname Linux 5e93c0d13461 5.4.0-149-generic #166-Ubuntu SMP Tue Apr 18 16:51:45 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux ok go-version go1.21.3 (gc) ok executable ~/bin/chezmoi ok upgrade-method replace-executable ok config-file no config file found ok source-dir ~/.local/share/chezmoi is a directory ok suspicious-entries no suspicious entries ok working-tree ~/.local/share/chezmoi is a directory ok dest-dir ~ is a directory ok umask 022 ok cd-command found /bin/bash ok cd-args /bin/bash info diff-command not set warning edit-command vi not found in $PATH ok edit-args vi ok git-command found /usr/bin/git, version 2.34.1 warning merge-command vimdiff not found in $PATH ok shell-command found /bin/bash ok shell-args /bin/bash info age-command age not found in $PATH ok gpg-command found /usr/bin/gpg, version 2.2.27 info pinentry-command not set info 1password-command op not found in $PATH info bitwarden-command bw not found in $PATH info bitwarden-secrets-command bws not found in $PATH info dashlane-command dcli not found in $PATH info doppler-command doppler 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 rbw-command rbw not found in $PATH info vault-command vault not found in $PATH info vlt-command vlt not found in $PATH info secret-command not set ```

Additional context

I also tried --no-tty, but it still doesn't work.

$HOME/bin/chezmoi init --no-tty --promptString testString=testString,testStringOnce=testStringOnce
twpayne commented 1 year ago

The --prompt* flags are for testing your config file template. They're not a way to pass arbitrary data to to the config file template.

Instead, use environment variables or template logic. See https://github.com/twpayne/chezmoi/discussions/3225.