This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2012年02月16日 23:51 by ncoghlan, last changed 2022年04月11日 14:57 by admin.
| Messages (4) | |||
|---|---|---|---|
| msg153516 - (view) | Author: Alyssa Coghlan (ncoghlan) * (Python committer) | Date: 2012年02月16日 23:51 | |
Currently, using add_subparsers() means that the entire list of subcommands is added to the main usage message. This gets rather unwieldy when there are a lot of subcommands. It would be nice if the add_subparsers() method accepted a "metavar" argument that would be substituted into the usage string instead of using the subparser list directly. |
|||
| msg180960 - (view) | Author: Chris Jerdonek (chris.jerdonek) * (Python committer) | Date: 2013年01月30日 01:52 | |
Have you tried setting the metavar property on the return value of add_subparsers()? I tried this, and it seems to work. It looks like the logic for _metavar_formatter() is the same no matter what the action type (specifically _SubParsersAction in this case): http://hg.python.org/cpython/file/e81cad0c722a/Lib/argparse.py#l554 |
|||
| msg180961 - (view) | Author: Chris Jerdonek (chris.jerdonek) * (Python committer) | Date: 2013年01月30日 01:59 | |
Actually, it looks like add_subparsers() may already support passing a metavar argument, but it's just not documented? |
|||
| msg291404 - (view) | Author: Martin Panter (martin.panter) * (Python committer) | Date: 2017年04月10日 02:42 | |
Thanks to Issue 11807, the documentation now lists "metavar". (However, it looks like a positional argument, rather than keyword-only, and its use seems to be discouraged, but those issues are not specific to "metavar".) Some points specific to "metavar" that I think could be clarified: 1. Metavar seems to affect the placeholder in the "usage" message, and a heading that precedes a multi-line list of commands, but it does not affect the presentation of the multi-line list itself. 2. The relationship between the "metavar" parameter of "add_argument" and "add_subparsers" needs clarifying. At the moment, there is a hyperlink, which implies that the description of add_argument’s parameter applies to add_subparsers. But it only discusses the "dest" parameter and CLI options (a.k.a. "optionals"), neither of which make sense in the context of subcommands. Issue 29030 (choices vs metavar) may be related. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:26 | admin | set | github: 58247 |
| 2017年04月10日 02:42:35 | martin.panter | set | versions:
+ Python 2.7 nosy: + martin.panter, docs@python messages: + msg291404 assignee: docs@python components: + Documentation, - Library (Lib) |
| 2013年01月30日 01:59:41 | chris.jerdonek | set | messages: + msg180961 |
| 2013年01月30日 01:52:31 | chris.jerdonek | set | messages: + msg180960 |
| 2013年01月30日 01:28:53 | chris.jerdonek | set | nosy:
+ chris.jerdonek |
| 2012年10月14日 10:26:35 | berker.peksag | set | versions: + Python 3.4, - Python 3.3 |
| 2012年10月09日 08:06:08 | kushal.das | set | nosy:
+ kushal.das |
| 2012年03月31日 11:38:24 | tshepang | set | nosy:
+ tshepang |
| 2012年02月16日 23:51:44 | ncoghlan | create | |