[issue9234] argparse: aliases for positional arguments (subparsers)
Adrian Sampson added the comment: Thanks for the pointer, Éric. Here's a quick patch that integrates the same functionality into the existing subparser class. -- keywords: +patch Added file: http://bugs.python.org/file20026/argparse-aliases.patch ___ Python tracker <http://bugs.python.org/issue9234> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9234] argparse: aliases for positional arguments (subparsers)
Adrian Sampson added the comment: Sorry I'm slow. Here's a new patch that includes tests. I'll also write documentation if that would be helpful, although I'm not very familiar with the style recommendations. -- Added file: http://bugs.python.org/file20034/argparse-aliases.patch ___ Python tracker <http://bugs.python.org/issue9234> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9234] argparse: aliases for positional arguments (subparsers)
Adrian Sampson added the comment: Great. I've added a simple example to the documentation for argparse. I also added a space to the comma separator in the alias list, but I'm worried that adding 'aliases:' will make the help less readable (especially if every command in a long list has aliases). -- Added file: http://bugs.python.org/file20073/argparse-aliases.patch ___ Python tracker <http://bugs.python.org/issue9234> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9234] argparse: aliases for positional arguments (subparsers)
Adrian Sampson added the comment: Thanks for the suggestion, Steven. I hadn't yet internalized the difference between dest and metavar. This version of the patch modifies metavar instead. Because it looks like this issue is up for 3.2b2, I've modified NEWS and ACKS (I hope this was the right thing to do). I also see the logic behind both help styles Steven depicts. If there's any interest, I can implement the other (hg) style or make it an option. -- Added file: http://bugs.python.org/file20101/argparse-aliases.patch ___ Python tracker <http://bugs.python.org/issue9234> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9234] argparse: aliases for positional arguments (subparsers)
New submission from Adrian Sampson : 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 <http://bugs.python.org/issue9234> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com