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)
... 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
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 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
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
File details
Details for the file jduargs-0.2.tar.gz
.
File metadata
- Download URL: jduargs-0.2.tar.gz
- Upload date:
- Size: 3.7 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | c58f694e696b43593b4a4eb2e50c29a983fd61d6644ad2a71d8643ad27f4284e |
|
MD5 | 452d4ca0ae01bca369b55127c9330871 |
|
BLAKE2b-256 | 904517413d8f5e05b77dfb0ecf57c2696ff1a950b8910a190c59a9b971d850c5 |