twpayne / chezmoi

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

autotemplate with a scope #2873

Closed sunn4room closed 1 year ago

sunn4room commented 1 year ago

Problem reproduction

chezmoi data

chezmoi:
  ...
  uid: "1000"
  ...
color:
  red: "#FF0000"
  ...

original config

number: "1000"
color: "FF0000"

autotemplate generate

number: "{{ .chezmoi.uid }}"
color: "{{ .color.red }}"

expect autotemplate

number: "1000"
color: "{{ .color.red }}"

So, I think chezmoi should give autotemplate a scope, for example chezmoi add --autotemplate=".color" xxx

Further discussion

I realize that chezmoi re-add will ignore the template file. It's natural that user should edit template file with chezmoi edit. If autotemplate has a scope, should chezmoi re-add include the autotemplate file?

twpayne commented 1 year ago

As mentioned in the previous issue that you opened (#2859), --autotemplate is fragile and naive and should not be used.

What you're asking for here is a context-aware --autotemplate that understands both the structure of the user's template variables and the structure of the file being converted into a template. This is extremely hard to do in a general way, and the proposed addition of a scope complicates the user interface to the point that it is likely easier for the user to create the template themselves.

If you can open a PR that implements what you want in a reliable way for all types of file then I would consider it, but in the short term I consider what you are requesting both effectively impossible and to have an unreasonably high ratio of implementation effort to user time saved.

halostatue commented 1 year ago

@twpayne Should --autotemplate be deprecated for removal in v3?

twpayne commented 1 year ago

@twpayne Should --autotemplate be deprecated for removal in v3?

Yes, I think it was too ambitious and too fragile.