[Python-Dev] Command line options for features in stdlib WAS: Pronouncement on PEP 389: argparse? (original) (raw)
Olemis Lang olemis at gmail.com
Tue Dec 15 17:46:44 CET 2009
- Previous message: [Python-Dev] Issue 3745 backwards incompatibility
- Next message: [Python-Dev] Summary of Python tracker Issues
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
/me starting a new thread because this goes beyond argparse itself
On Tue, Dec 15, 2009 at 4:34 AM, Antoine Pitrou <solipsis at pitrou.net> wrote:
Steven Bethard <steven.bethard gmail.com> writes:
Because people are continuing this discussion, I'll say again that argparse already supports this: Well I think the point is that if there is a default, the default should be sensible and not run against expectations.
+1
It would probably be fine not to have a default at all, too.
-1
I really think that it's good to expect the same (similar) behavior when the same options is accepted by multiple commands. In the end that's a decision of the people implementing the concrete command line tool, but it is nice to rely on something like : «if you forgot, or don't remember or don't know about it then the std decision is performed»
Now that you mention all this , I follow up with a comment that is more about -v switch . Most of the time I realize that command line apps have logging capabilities and should also allow different verbosity levels (e.g. -q, -s, -v, --noisy) . The good thing is that this always can be done the same way (i.e. using log levels defined in logging module ) . The not so good news is that (in practice) coders have to do it over and over every time they create a new command line app, and users might need to remember those switches if the author used different names . My suggestion is that it would be nice to identify std switches and add support for configuring the cmd-line parser and logger instance OOTB
{{{ #!python import argparse import logging
if name == ’__main__’: # create the parser parser = argparse.ArgumentParser(description=’XXX’) # add the arguments ... # add args for verbosity level logging.add_args(parser) # parse the command line args = parser.parse_args() # configure logging -- # probably omitted if an option handles this logging.fileConfig(*cfg_args) # setup the logger instance logging.argparseConfig(getLogger('xxx'), args) }}}
The same reasoning could probably be extended to other modules in stdlib (e.g. default encoding, testing, ...). It's probably a good idea to define a set of (std) command line args for std features (preferently without conflicting with existing standards ;o) and provide shortcuts to ease configuration process when building command line tools
PS: This thread might also be related to the previous one about logging configuration using dicts
-- Regards,
Olemis.
Blog ES: http://simelo-es.blogspot.com/ Blog EN: http://simelo-en.blogspot.com/
Featured article: Automated init. - http://bitbucket.org/osimons/trac-rpc-mq/changeset/e122336d1eb2/
- Previous message: [Python-Dev] Issue 3745 backwards incompatibility
- Next message: [Python-Dev] Summary of Python tracker Issues
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]