[issue7284] argparse - display version in usage by default
Steven Bethard
report at bugs.python.org
Sat Mar 26 11:20:13 CET 2011
Steven Bethard <steven.bethard at gmail.com> added the comment:
In argparse, you could so something like:
version = "2.7"
parser = argparse.ArgumentParser(
description="My program XXX, version " + version)
parser.add_argument('-v', action='version', version=version)
That would then produce:
usage: PROG [-h] [-v]
My program XXX, version 2.7
optional arguments:
-h, --help show this help message and exit
-v show program's version number and exit
Is that acceptable? This is basically the style of svn:
$ svn help
usage: svn <subcommand> [options] [args]
Subversion command-line client, version 1.6.15.
...
I see though that vi puts the full name and version before the usage (which is currently impossible in argparse):
$ vi --help
VIM - Vi IMproved 7.0 (2006 May 7, compiled Sep 19 2009 17:22:08)
usage: vim [arguments] [file ..] edit specified file(s)
...
Most other programs I tried didn't give a version number at all, though some did give a full name before the usage:
$ hg
Mercurial Distributed SCM
...
$ hg clone --help
hg clone [OPTION]... SOURCE [DEST]
...
$ git
usage: git [--version] [--exec-path[=GIT_EXEC_PATH]] [--html-path]
...
$ emacs --help
Usage: emacs [OPTION-OR-FILENAME]...
...
I guess we could add, say, a headline= option to ArgumentParser which would then be printed before the usage message if it's really crucial to have that message first... I'd rather not though if the description= approach is acceptable to you, since adding headline= would add more complexity to an already complex ArgumentParser constructor.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue7284>
_______________________________________
More information about the Python-bugs-list
mailing list