Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork34.1k
Closed
Description
Bug report
Bug description:
I'm defining a argparse parser that works like vim:
support a file as a positional:
vim file.pyor reading from stdin:
cat file.py| vim -
So I write a mutually exclusive group:
importargparseap=argparse.ArgumentParser(description="fake vim")mg=ap.add_mutually_exclusive_group(required=True)mg.add_argument("input",nargs="?")mg.add_argument("-",dest="from_stdin",action="store_true")args=ap.parse_args()
When I use "-h" to show the help message, the "|" in usage line is dropped, as if the 2 arguments are not mutually exclusive:
usage: fake_vim.py [-h] [-] [input]However, if Iswap the 2add_argument lines in the source code:
importargparseap=argparse.ArgumentParser(description="fake vim")mg=ap.add_mutually_exclusive_group(required=True)mg.add_argument("-",dest="from_stdin",action="store_true")mg.add_argument("input",nargs="?")args=ap.parse_args()
It magically behaves correctly:
usage: fake_vim.py [-h] (- | input)CPython versions tested on:
3.9, 3.11
Operating systems tested on:
Windows
Linked PRs
Metadata
Metadata
Assignees
Labels
Projects
Status
Doc issues