-
Notifications
You must be signed in to change notification settings - Fork 506
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add more config management functions #2215
Comments
Thank you for the extremely complete and well-researched feature request! #2218 and #2237 add some of the functions. For For |
Thank you! I was able to clean up my templates significantly.
Understandable. I was able to find the following, but it may not be an easy fix. Unfortunately I'm not the expert when it comes to Go, just more of a beginner with a descent understanding of templates from working with Hugo: https://github.com/go-ini/ini
The only issue I'm encountering is you can't pipeline or assign templates from what I can tell, so I'm not sure how to resolve at the moment. The |
Ah, good point. Yes, I don't think there's a way to capture the output of As a drive-by comment, it might be possible to use the template data for your specific disclaimer case. If your disclaimer template in
and you then invoke it with:
you might get the effect you want with less code for now, at least until |
Thanks, that is very similar to what I ended up doing but I ended up incorporating the
|
OK, I've added For
Instead, for generating For So, closing this as completed. Feel free to continue discussions, however. |
Thank you kindly for working on this. I will contribute more via a PR if I am able to do so at some point.
While I agree that there is no standard INI format like you'd see with YAML, there is a consistent format used by a majority of programs that I commonly interact with.
That is unfortunate to hear, but I just linked with one of the first presentable Go packages I found. There may be others better suited for the task but I really don't know the best way to evaluate what would be an ideal module to create a function from, especially one that may allow an optional parameter to handle variations. Again, thank you for your efforts as they make the process of utilizing chezmoi more friendly than implementing a bunch of custom templates. I'll explore implementing the additional functionality of writing to an INI file within the |
Handling mixed-case keys is a long standing bug/feature in the viper library that chezmoi uses for parsing its config file. See #463. |
#2279 tracks the feature request for |
Is your feature request related to a problem? Please describe.
Functions are primarily limited to the Sprig library, which does not handle a lot of common config management functions.
Describe the solution you'd like
I'd like to see more functions available to address config management. The main functions here would to:
fromToml
toToml
fromIni
toIni
replaceRE
partial
andreturn
comment
Additionally any merge functionality that may not be covered by Sprig functions. This helps streamline a common use case of overriding default config file values.
fromToml
,toToml
,fromIni
, andtoIni
are all pretty self-explanatory. Here are some examples of where those are already implemented in Go.replaceRE
is the name of a function in Hugo1 that allows for proper pipelining2 and a limit parameter.partials
are like templates3, except that you can do pipelining on the results, with an optionalreturn
function4 in the partial template.comment
is very similar to the indent Sprig functions, and takes inspiration from an Ansible filter5. This would take either a single or multiline string and adds the specified comment character(s) at the beginning of each newline. A common use case for this is a disclaimer for users that may try editing a file directly outside of the sourceDir:.local/share/chezmoi/.chezmoitemplates/disclaimer
.local/share/chezmoi/private_dot_config/example/exampleconfig.conf.tmpl
Describe alternatives you've considered
I've already to the larger extent implemented these in each file template, but it requires a lot of duplication.
Footnotes
https://gohugo.io/functions/replacere/ ↩
https://github.com/Masterminds/sprig/issues/86 ↩
https://gohugo.io/templates/partials/ ↩
https://gohugo.io/templates/partials/#returning-a-value-from-a-partial ↩
https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html#adding-comments-to-files ↩
The text was updated successfully, but these errors were encountered: