I'm in a situation where I'm dealing with parsing the command line
twice to resolve a problem where when I specify a config file to parse
through a command line option and then parse the config file it will
of course override the command line. To solve this I'm parsing the
command line again after parsing the config file.
Any thoughts on a proper method of handling this scenario that doesn't
seem redundant? I think I may be overlooking the standard flow of
this operation in favor of making things simple for the end user but
possibly mucking with a configuration management style that I'm not
100% indepth with at the moment.
- Shane
In the same situation I wrote an ugly solution with my own settings.py
module:
https://gist.github.com/1830236
This is only the first part of it. Second part consists of blocks like that:
if '--parameter' in sys.argv:
PARAMETER = True
elif '--no-parameter' in sys.argv:
PARAMETER = False
It sucks, yeah, but works for me :-). The most unattractive features are
that it causes to:
- write --help content by hand;
- write 4 lines of code per parameter;
- doublecheck every of that lines to avoid mistakes.
Just decided to share my butthurt. Don't use it! :-)
14.02.2012 23:26, Shane Spencer пишет:
--
Andrew
I think what I'd like to do is add a standard --flagfile option that
would load options from the file as if they appeared in the command
line in place of the --flagfile. However, the config files
interpreted by parse_config_file are executable python and I'm a
little uneasy about enabling something like that by default. A more
limited flag-only format would be nice, although maybe not worth the
complexity.
-Ben
There's not currently a good solution for this; the options module
assumes that you'll use either command line or config files but not
mix the two (I think friendfeed only ever used the command-line side
of the interface)...
-Ben
- Didip -