A drop-in replacement to Python's built-in argparse, that provides the capability to argparse any arbitrary string, not just command line arguments.
Project description
argparsethis
A drop-in replacement to Python's built-in argparse, that provides the capability to argparse any arbitrary string, not just command line arguments. Is sourced from https://github.com/python/cpython/blob/3.8/Lib/argparse.py.
Installation
pip[3] install argparsethis
Usage
When creating your ArguementParser, just override the parameter input_list
as a list of strings to parse. We recommend using shlex
to split any raw strings into a list correctly. If input_list
is not overridden, it will use standard command line arguments like normal. Also adds the exit_on_error
parameter, if you want to raise an ArgumentException
in the event of a parsing error or printing out the help, instead of just exiting (the default behavior).
import shlex
import argparsethis as argparse
# Argument parsing which outputs a dictionary.
def parse_args(input_str):
#Setup the argparser and all args
input_list = shlex.split(input_str)
parser = argparse.ArgumentParser(input_list = input_list, exit_on_error = False)
parser.add_argument("-q", "--quiet", help="suppress extra output", action="store_true", default=False)
return parser.parse_args()
argv1 = parse_args("test -h")
argv2 = parse_args("test -q")
if not argv2.quiet:
print("LOUD NOISES")
else:
print("Please be quiet")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file argparsethis-1.1.2.tar.gz
.
File metadata
- Download URL: argparsethis-1.1.2.tar.gz
- Upload date:
- Size: 22.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.6.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 458893cb9c84968dc6985deb76f03b0ec32cfb489f26c740936b9ebca624d1a6 |
|
MD5 | 57b71661f6cecf60a6ad105977dde4e4 |
|
BLAKE2b-256 | 3ea35ab4552c0ea48234360480c948cdac08c6272f009f196b4e957b88ecf4e9 |
File details
Details for the file argparsethis-1.1.2-py3-none-any.whl
.
File metadata
- Download URL: argparsethis-1.1.2-py3-none-any.whl
- Upload date:
- Size: 23.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.6.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 41581e28501a3d6b5e5c0f449fdd5575e879d6a20f4f2d557d6636a6194e2a90 |
|
MD5 | ecef67ad81b1fbdeb95a984c7877a3d3 |
|
BLAKE2b-256 | f32616e301f9d93f7879ee198165f31dc2ab4e5a6f26b8b831fe1726ba0d68e7 |