[issue9234] argparse: aliases for positional arguments (subparsers)

Adrian Sampson report at bugs.python.org
Mon Jul 12 22:09:07 CEST 2010


New submission from Adrian Sampson <asampson at cs.washington.edu>:

The argparse module supports "subparsers," which allow CLI tools to support invocation of subcommands (much like the svn or hg programs). For these subcommands, it is often useful to allow multiple names for the same command. For instance, in Mercurial, "hg blame" does the same thing as "hg annotate".

You should be able to create subparsers with command aliases, like this:
>>> subparsers.add_parser("annotate", aliases=('ann', 'blame'))

The help message for the program should display the aliases alongisde the command names.

I'm attaching an example script that adds an Action to the library to accomplish this. This isn't a patch, but if this approach seems right to other people, I'll turn it into a patch.

Here's this bug on argparse's old tracker:
http://code.google.com/p/argparse/issues/detail?id=23

----------
components: Library (Lib)
files: aliases.py
messages: 110130
nosy: asampson
priority: normal
severity: normal
status: open
title: argparse: aliases for positional arguments (subparsers)
type: feature request
versions: Python 2.7
Added file: http://bugs.python.org/file17971/aliases.py

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue9234>
_______________________________________


More information about the Python-bugs-list mailing list