-
Notifications
You must be signed in to change notification settings - Fork 41
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
feat: Add TOML support for config files #741
Conversation
simplify readfrom function logic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neat work. Left some comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great! Thank you so much for putting the effort into implementing this <3 Just a couple of nits before approving.
Co-authored-by: Alejandro García Montoro <alejandro.garciamontoro@gmail.com>
Co-authored-by: Alejandro García Montoro <alejandro.garciamontoro@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thank you!
Summary
This pull request adds TOML support for config files.
The
ReadFromJSON
function has been refactored into a unifiedReadFrom
with the same signature that determines the filetype by the extension the file has, if the extension is.toml
a TOML decoder is used, following with JSON by default.Code chagues
Decoder
interface that we can use to simplify the unmarshalling logic in the code (try to decode, search for fallback, etc). Now we just pass theDecoder
(orDecoderFactory
) around and the rest of the logic is the same for all decoders.JSONDecoder
andTOMLDecoder
(fromjson.Decoder
andtoml.Decoder
) since their signatures are different and also to allow TOML to show up better errors on decoding failures.ReadFrom
method that should take care of everything.Potential improvements
I focused on the Decoding part only, but if we plan to use it also as a encoder (to generate config files) we need to improve the data structure, interfaces and names around. It shouldn't be much but something to take into consideration.
I like to have "
Codec
" interfaces that take care of encoding/decoding around and create implementations for whatever thing I want to support, to I would go in that direction. Maybe in another PR if this one gets in.Why
TOML files are way more readable for the end user, and we can put comments in the file for explanation of fields, better sort keys, etc.
Even better could be using the TOML's library capabilites to add comments on TOML files. I potentially see this in a way that:
Test run
Performed a trial deployment with
config
anddeployer
TOML files. Didn't test all commands manually.Ticket Link
--