https://github.com/xmonader/suggestparse
argparse extension to allow command suggestions for invalid commands
https://github.com/xmonader/suggestparse
argparse argument-parser python3 suggestions
Last synced: about 1 month ago
JSON representation
argparse extension to allow command suggestions for invalid commands
- Host: GitHub
- URL: https://github.com/xmonader/suggestparse
- Owner: xmonader
- License: bsd-3-clause
- Created: 2017-11-18T18:42:46.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-11-18T20:05:18.000Z (over 8 years ago)
- Last Synced: 2025-05-14T04:34:25.914Z (11 months ago)
- Topics: argparse, argument-parser, python3, suggestions
- Language: Python
- Size: 5.86 KB
- Stars: 7
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# suggestparse
argparse extension to allow command suggestions for invalid commands based on difflib closest_matches function.
## Installation
To install
```pip install suggestparse```
## Example
```python
def test():
parser = SuggestingArgumentParser()
parser.add_argument('--add', '-a', help='add')
parser.add_argument('--edit', '-e', help='edit')
parser.add_argument('--delete', '-d', help='delete')
parser.add_argument('--view', '-v', help='view')
print(parser.parse_args())
if __name__ == '__main__':
test()
```
So if you type `--vew` by accident or things like `git comit` or `git clon` you will see something like that.
```
$ python3 suggestparse.py --vew
Did you mean: ['--view']
usage: suggestparse.py [-h] [--add ADD] [--edit EDIT] [--delete DELETE]
[--view VIEW]
suggestparse.py: error: unrecognized arguments: --vew
```