-
Notifications
You must be signed in to change notification settings - Fork 23
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
Provide a pluggable interface for alternative configuration value sources (files, env vars) #44
Comments
So, this is not a bad idea, but there are some thorny sub-issues. A config file has more intrinsic flexibility than a flat name=value parameter list. In particular, it can have hierarchy that parallels hierarchy in some object a la #30 . Contrariwise, an environment variable has even less intrinsic flexibility being a flat string that needs splitting/quoting rules. So, one can maybe just implement the simple case, but it probably wouldn't be long before someone asked for maximum analogousness of an object with a config file (saying they never use command-line args or environment variables) which would then allow more than the other cases could. Just a comment on the idea. I am open to working on a pull request if someone wants to try. To me it seems like almost a parallel "cfParseGen" module would be more likely to be well-received. Part of what makes something like |
Yeah, good points. In part, that's why I think a pluggable API might be the way to go, instead of fixating on a particular form and shape of config files - basically, cligen would be split up into layers - one which parses function defs and objects and passes some sort of summary to another part that takes the names and applies them. The way I've enjoyed a feature like this is for the slightly more complex applications that have several subcommands and several tweaks that can be controlled from the command line. [txpool]
option_a = y which I can override with of course, this shouldn't break the fantastic for-dummies mode that cligen has and just works, for the simple case where all this machinery is not needed! |
#46 is partially related |
So, as I mentioned in #30, you can get your "end CLI user functionality" of merging config file and environment variable sources for command parameters with whatever a user enters on a given command line without any more All you really need is to have some In a So, we could probably just provide some default |
Well, I went ahead and added a default If you (or anyone else) wants to write something that uses the Nim stdlib's Personally, I am my own primary user for all the commands I write with |
cool, thanks! I'll check that out for sure and get back when I have some feedback :) |
Cool. About the only real question in my mind was whether There are pros & cons...Making users doing simple commands have to use BTW, I didn't say before, but the "one source of truth", at least in |
Well, I gave it almost a week, but decided I should not leave a temporary interface in the git repo for too long. So, I went ahead and made that |
A nice feature of command lines is if you can stick the same runtime option values in config files or pick them out from environment variables.
Since cligen builds a mapping of name-to-value, would be interesting if there was support for building up such chains of option-sources from one source of truth about what the valid options are - specially interesting if #30 happens and options can be gathered in objects that are a little bit more complex.
This API would need to give the parser names and types to work with as well as a way to feed back the values read. Further, it would have to support prioritizing, so that something on command line overrides config file.
The text was updated successfully, but these errors were encountered: