A very easy to use argument parser.
Project description
fargv: The laziest command-line argument parser
Installation
pip3 pip install --user --upgrade git+https://github.com/anguelos/fargv
Usage in 3 Simple Steps!
Fast argument parser
- Import
"""
The script's docstring Becomes the general description in the help if defined
"""
from fargv import fargv
- Define a dictionary with default parameters
params = {
"anInt": 1,
"aFloat": 0.1,
"aBoolean": False,
"anotherBoolean": True,
"aString": "Hello",
"aStringReference": "{aString} World",
"anIntWithHelp": [2,"This would be the help"],
"aChoice": [("choice1","choice2","choice3","choice4"),"And this must be the help"],
"aPositionalSwitch": [set([]), "This is a convenient way to pass colections of things"]
}
- Parse user provided argv to override defaults
new_params, help_str = fargv(params)
- In shell:
my_program -anInt 34 -aFloat=2.3 -aBoolean -anotherBoolean=False
Features:
- Type checking
- Automatic help generation
- Params usable as dictionary or struct
- Can read environmental variables as well
- macro-parameters
- fast autocomplete generation
- Switches with positional values
Autocomplete
Static autocomplete for any program using fargv can be enabled with a single command.
The following command enables autocomplete for fargv_demo.py in the current shell where it is run.
source <(./examples/fargv_demo.py -bash_autocomplete)
fargv_demo.py should be an executable file employing the shebang (#!/usr/bin/env python3) or something equivalent. For a temporary solution, the autocomplete bash code can go in a script in /etc/bash_completion.d or in .bashrc.
Switch Macros
A switch might be a macro for other switches. This allows for example to break many files into a single root switch and all other switches beeing file names relative to that path.
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 fargv-0.1.7.tar.gz
.
File metadata
- Download URL: fargv-0.1.7.tar.gz
- Upload date:
- Size: 8.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.27.1 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.62.3 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e65178e3339f0f18a6c141e354f5c345ca613cf9373e2cc8330a3c6b4f916330 |
|
MD5 | 95ab14fc286178a6a1819928aada90d8 |
|
BLAKE2b-256 | 8c2c1c524fcf9f79150860f202c94496a816758606e3e1d1d3ebc7973ed96c92 |
File details
Details for the file fargv-0.1.7-py3-none-any.whl
.
File metadata
- Download URL: fargv-0.1.7-py3-none-any.whl
- Upload date:
- Size: 11.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.27.1 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.62.3 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 263964ed41eaaf37f2df671b1ba03d33189412c3490e8b9836583589af4d9f0d |
|
MD5 | b153a9b65a74f5da84363190f338a76d |
|
BLAKE2b-256 | b577d2a3f07ca7758f87507e112872458540e4bf43672d897a366980ce8dd76e |