Closed x80486 closed 1 year ago
I think what would be missing here shouldn’t be too hard to add, and that’s an unconditional "halt" template function.
It might work as something like:
...
[user]
email = "{{ .git.gitlab.email }}"
name = "{{ .git.gitlab.name }}"
{{- if stat (joinPath .chezmoi.homeDir ".ssh/gitlab-personal.pub")) }}
signingKey = "{{ .chezmoi.homeDir }}/.ssh/gitlab-personal.pub"
{{ else }}
{{ halt "Missing ~/.ssh/gitlab-personal.pub" }}
{{ end }}
This is imperfect and may be dangerous for normal execution cases, but the idea could work.
You can use the existing fail
template function for this.
Good to know and good to know that such a template function already exists.
Description
I would like to be able to be able to run some checks in a way that's not invasive to fail (or not) the generated file based on a given template.
For instance, I have a
config
file forGit
with auser
section that's similar to this:So if I try to generate the file based on this template, it should fail because
{{ .chezmoi.homeDir }}/.ssh/gitlab-personal.pub
is not present (if that's the case).Describe Solution(s) You Would Like
{{ .chezmoi.homeDir/.ssh/gitlab-personal.pub | file_exists }}
Describe Alternatives You Have Considered
N/A