Skip to main content

A simple command line argument parser package.

Project description

jduargs

Simple command line argument parser.

Installation

> pip(3) install (-U) jduargs

and

from jduargs import ArgumentParser

Methods

def add(self, key: str, short: str, type: type = Type[str], required: bool = True, description: str = "")

... to add an expected argument. The parameters are:

  • key: the name of the parameter
  • short: the short version of the key, as a single caracter
  • type: the parameter type class
  • required: define if the argument is mandatory or not. If set to False and the parameter is not provided, the default value is set by the type constructor
  • description: explanation of what this parameter is used for. If no description is provided, an empty string is used instead
def from_json(self, path: str)

... to import the expected parameters from a json file. The dictionnary keys are the parameters name. For each key, it should contains the "short" and "type" keys as strings, and a required key as a boolean.

def to_json(self, filename: str)

... to export the parameter dictionnary to a json file.

def compile(self, args: List[str])

... to parse the provided argument list with respect to the defined parameters.

Usage

First create an instance of the parser:

parser = ArgumentParser()

Then add the expected arguments to parse:

parser.add("path", "p", str, False)
parser.add("offset", "o", int, True)

Compile the parser with the input arguments provided from command line:

parser.compile(sys.argv[1:])

From here you can access each parameters with the simple bracket operator:

path = parser["path"]
offset = parser["offset"]

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

jduargs-0.3.5.tar.gz (4.5 kB view details)

Uploaded Source

File details

Details for the file jduargs-0.3.5.tar.gz.

File metadata

  • Download URL: jduargs-0.3.5.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.4

File hashes

Hashes for jduargs-0.3.5.tar.gz
Algorithm Hash digest
SHA256 61c99919210a28f111e3428ae54db11b95bd6fc8054d41f8dbb12c9df167eed6
MD5 c9ab1a646218b98254d09b81005e5115
BLAKE2b-256 d2d6e2c89a552e894b7001d8dab8b0ab0b9e9f8636af7b2db350b11326f40db3

See more details on using hashes here.

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