Closed ReallyLiri closed 7 months ago
Thanks for the PR @ReallyLiri. Not sure if this should be merged in the core as it's a bit of a niche usecase. Config files generally have fixed structures, so keys disappearing when marshalling / dumping is unconventional. If a key has a nil or empty value, that's still valid.
In my use case, the CLI has a very vast number of options, while in practice, the user would only want to customize a very small amount of them. So if the marshalled config will contain all the possible keys, it will just create lots of unused portions. I do understand if its not a use case you'd like to support
Understood. I think this wouldn't be ideal to merge into the core. Thanks again for the PR.
Added
MarshalWithConf
overload that allows passing an option to omit empty values from when marshalling. This is useful when "dumping" config to a file that will later be merged with other such configs, then empty values won't overwrite some valid value. In addition its useful for dumping very large configs created using a struct, with many optional values.