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
Automatic handling of deprecated values #115
Comments
Sounds like a great idea! For reference, I use this in the In-a-dyn project to handle a deprecated setting https://github.com/troglobit/inadyn/blob/master/src/conf.c#L62 having a callback instead would be preferable. Only comments I have are with style requests for your upcoming PR:
Basically, it's Linux Coding Style. |
Any progress on this? |
I don't have any time to work on this at the moment. |
@lanoxx Fully understandable, just curious, take care! :) |
I have been using the new CFGF_MODIFIED flag to accomplish option migration. Something like this:
It would be nice to be able to follow that up with |
@peda-r Hey, that's a great idea! |
If you are referring to the I don't want to think about what can go wrong if the instantiated options in |
Currently libconfuse has the option to deprecate config options and also to automatically drop deprecated config options. For deprecated config options that are not flagged to be dropped a warning is printed. For use cases where the user manually edits a config file this is fine, but for use cases where we want to perform automatic migration of deprecated values this is not enough.
I think it would be nice if we had the ability to add a deprecation callback handler in libconfuse which can notify the application of deprecated values in the configuration file. This would give the application a change to migrate these values automatically. The way I imagine this would be as following:
We add the
CFGF_DEPRECATED
to some existing but now obsolete config option, like this:We define a deprecation handler callback function type that can be implemented by the application. It gets passed the
config
pointer, theoption_name
of the deprecated option and an optionaluser_data
pointer as arguments:The
deprecationFunc
gets called for each deprecated value that remains in the config file. The app can handle the deprecated value and migrate it to some other option. By returningTRUE
orFALSE
from the deprecation function the app can indicate if the value was correctly migrated. IfTRUE
is returned no warning should be logged for the deprecated option, otherwise a warning will be logged (current behavior).If additionally the flag CFGF_DROP is specified and the deprecation handler returned
TRUE
, then the option is automatically removed.When we call
cfg_parse
, we pass additional parameters with thedeprecation_handler
function and theuser_data
as callback:Please let me know what I think. Maybe I missed something, or if if this is already possible in libconfuse then it would be nice to know how.
The text was updated successfully, but these errors were encountered: