Skip to main content

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.

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

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)
    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")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

argparsethis-1.1.1.tar.gz (21.8 kB view hashes)

Uploaded Source

Built Distribution

argparsethis-1.1.1-py3-none-any.whl (23.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page