A fresh new way to handle cli
Project description
ArguMint
A fresh new way to handle cli
How to use it
from argumint import ArgStruct, ArguMint
from typing import Literal
import sys
def sorry(*args, **kwargs):
print("Not implemented yet, sorry!")
def help_text():
print("Build -> dir/file or help.")
def build_file(path: Literal["./main.py", "./file.py"] = "./main.py", num: int = 0):
"""
build_file
:param path: The path to the file that should be built.
:param num:
:return None:
"""
print(f"Building file {path} ..., {num}")
from aplustools.package import timid
timer = timid.TimidTimer()
arg_struct = {'build': {'file': {}, 'dir': {'main': {}, 'all': {}}}, 'help': {}}
# Example usage
builder = ArgStruct()
builder.add_command("build")
builder.add_subcommand("build", "file")
builder.add_nested_command("build", "dir", {'main': {}, 'all': {}})
# builder.add_subcommand("build", "dir")
# builder.add_nested_command("build.dir", "main")
# builder.add_nested_command("build.dir", "all")
builder.add_command("help")
print(builder.get_structure()) # Best to cache this for better times (by ~15 microseconds)
parser = ArguMint(default_endpoint=sorry, arg_struct=arg_struct)
parser.add_endpoint("help", help_text)
parser.add_endpoint("build.file", build_file)
# If it's a script, the first argument is the script location, but if it's a command it's not in the list
sys.argv = ["build", "file", "./file.py", "--num=19"] # sys.argv[1:] # To fix it not being a command yet
parser.parse_cli(sys, "native_light")
print(timer.end())
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
argumint-1.0.3.tar.gz
(19.0 kB
view details)
Built Distribution
argumint-1.0.3-py3-none-any.whl
(19.2 kB
view details)
File details
Details for the file argumint-1.0.3.tar.gz
.
File metadata
- Download URL: argumint-1.0.3.tar.gz
- Upload date:
- Size: 19.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 241b85d2ee6b9c6591381e176793253ac4ba891c9d47588d363ca47a1ad9c6ad |
|
MD5 | a8a4c1351379b084afd74c2b15b24f7c |
|
BLAKE2b-256 | 78cb31def08c50504740b7d296e3c51c3ba87f73ddf23cd253f709dd12383571 |
File details
Details for the file argumint-1.0.3-py3-none-any.whl
.
File metadata
- Download URL: argumint-1.0.3-py3-none-any.whl
- Upload date:
- Size: 19.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 70147438ee5373dcc5b5936740829cefa3788b2d01ed18f853fcabbc5395b9ef |
|
MD5 | efbb79f2c10c5738fc7b460e783a7316 |
|
BLAKE2b-256 | 60133da1c8f14608cad00b668e7388b57f62c486bf9349f60aad41c3b1984e90 |