ZParser Cli Argument Library. Nothing comes after Z
Project description
ZParser2 Cli Argument Parsing Library
zparser2 is probably the simplest most opinionated argument parsing library. Lot's of conventions, zero configuration!
If you add the @z.task notation to a function, it automatically become available to the CLI.
The function's parameters are what the CLI will expect. If notations are given, type will be enforced.
The file in which the function is located will be the module in which the function will be available.
The downside is that you can only have two layers in your cli. That being said, more than that would be too complex and less than that you don't really need a library.
Example
Let's say you have 3 files:
math_functions.py
"""here we do math"""
from zparser2 import z
@z.task
def duplicate_number(x: float):
"""returns twice the value of x"""
return 2*x
@z.task
def triple_number(x: float):
"""returns 3 times the value of x"""
return 3*x
string_functions.py
"""string processing"""
from zparser2 import z
@z.task
def add_square_brackets_to_string(x: str):
"""x -> [x]"""
return f"[{x}]"
@z.task
def first_word(x: str):
"""returns the first word of a string"""
return x.split(" ")[0]
@z.task
def last_word(x: str):
"""returns the first word of a string"""
return x.split(" ")[-1]
@z.task
def another_task(somestring: str, some_int: int, workdir=None, root_url=None):
"""description of the task"""
print(f"somestring={somestring}")
print(f"some_int={some_int}")
print(f"workdir={workdir}")
print(f"root_url={root_url}")
mycli.py
#!/usr/bin/env python3
import zparser2
import math_functions
import string_functions
if __name__ == "__main__":
zparser2.init()
Output
(env2) mdiez@batman:~/code/zparser2/example$ ./mycli.py
./mycli.py <plugin_name> <task>
Plugin list:
math_functions - here we do math
string_functions - string processing
(env2) mdiez@batman:~/code/zparser2/example$ ./mycli.py string_functions
You need to specify a task
--------------------------------------------------------------------------------
string processing
./mycli.py string_functions <task>
Plugin alias: []
Tasks:
add_square_brackets_to_string - x -> [x]
another_task - description of the task
first_word - returns the first word of a string
last_word - returns the first word of a string
(env2) mdiez@batman:~/code/zparser2/example$ ./mycli.py string_functions another_task
You need to specify the required arguments [somestring, some_int]
--------------------------------------------------------------------------------
description of the task
Usage:
./mycli.py string_functions another_task somestring some_int [--workdir workdir] [--root_url root_url]
Positional arguments:
somestring - <class 'str'>
some_int - <class 'int'>
Optional arguments:
--workdir (Default: None) -
--root_url (Default: None) -
(env2) mdiez@batman:~/code/zparser2/example$ ./mycli.py string_functions another_task blah 42 --root_url https://blah.com
somestring=blah
some_int=42
workdir=None
root_url=https://blah.com
How to build & publish
python3 -m buildpython3 -m twine upload --repository testpypi dist/*python3 -m twine upload --repository pypi dist/*
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file zparser2-0.0.5.tar.gz.
File metadata
- Download URL: zparser2-0.0.5.tar.gz
- Upload date:
- Size: 8.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b6405d4c9cdd2df3fac14bf30587bf1ccae91172e7d3aeb2bc4eed3d4f3cf70a
|
|
| MD5 |
23ffd89b830234e6caa4c70293fa93be
|
|
| BLAKE2b-256 |
9b350e0168459a64f3989d4df8f3bb6545668b7bb15daf001df682b15c1680f1
|
File details
Details for the file zparser2-0.0.5-py3-none-any.whl.
File metadata
- Download URL: zparser2-0.0.5-py3-none-any.whl
- Upload date:
- Size: 7.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e7bff1455a47f7b54dc8ced1b6d5be3f788c268b30805b03d0cc09811a7d3cc0
|
|
| MD5 |
b9f9c6b6c3fd67e96e890786c0424919
|
|
| BLAKE2b-256 |
498deda63622646bbb681b4679507d0ba264a9635f61718b982a5fe4ad227c55
|