twpayne / chezmoi

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

Add a way to easily invoke chezmoi non-interactively even if using prompt* functions with answers on the CLI or from a file #2185

Closed segevfiner closed 2 years ago

segevfiner commented 2 years ago

Is your feature request related to a problem? Please describe.

To support non-interactive usage of chezmoi when using for example codespaces or devcontainers, you need to manually add logic to run non-interactively to your config file. This is cumbersome and serves as an hurdle for using your dotfiles in this scenario.

Describe the solution you'd like

Add a way to work non-interactively even when using prompt* functions by allowing to supply answers on the CLI or by loading an answers file containing them.

Describe alternatives you've considered

Keep doing this manually in the config file template, which is no fun.

Additional context

I'm not sure devcontainers allow to easily mount such an additional file, so to use answers from a file ATM you might have to commit it to the dotfiles repo.

twpayne commented 2 years ago

What exact workflow would you like to see here? As you say, this is currently achievable with a config file template (I use it myself), and the improvements in #2204 will make this more concise. Note also that c90a95e78cca2835045c7e5e2e39c9997159787c fixes a bug that prevented prompt* from working well when piping stdin from a file.

segevfiner commented 2 years ago

The idea is being able to supply such values from the outside without having to hard code them for each configuration or machine you use into your config file template., and having to remember to be non-interactive for development containers/codespaces, etc. When you need to be non-interactive, you can just pass such a values file.

twpayne commented 2 years ago

Is the following what you have in mind?

If my config file template contains something like:

{{ $hasGUI := promptBoolOnce . "hasGUI" "Does this machine have a GUI" }}

then I can run chezmoi init with a values file called myvalues.toml containing something like:

hasGUI = true

and then invoke chezmoi init with something like:

$ chezmoi init --values=myvalues.toml $GITHUB_USERNAME

and then chezmoi init would take the hasGUI value from myvalues.toml instead of prompting for it?

ndwarshuis commented 2 years ago

chezmoi init --values=myvalues.toml $GITHUB_USERNAME

This, or something like the --prompt* flags that work with --init when using chezmoi execute-template, except for chezmoi init.

twpayne commented 2 years ago

This, or something like the --prompt* flags that work with --init when using chezmoi execute-template, except for chezmoi init.

Thanks for the suggestion. This is simpler and done in #2274.