chezmoi icon indicating copy to clipboard operation
chezmoi copied to clipboard

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

Open segevfiner opened this issue 2 years ago • 4 comments

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.

segevfiner avatar Jun 30 '22 07:06 segevfiner

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.

twpayne avatar Jul 21 '22 14:07 twpayne

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.

segevfiner avatar Jul 21 '22 20:07 segevfiner

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?

twpayne avatar Jul 26 '22 19:07 twpayne

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.

ndwarshuis avatar Aug 02 '22 03:08 ndwarshuis

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.

twpayne avatar Aug 19 '22 17:08 twpayne