Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/adalfarus/argumint
A fresh new way to handle cli
https://github.com/adalfarus/argumint
Last synced: about 1 month ago
JSON representation
A fresh new way to handle cli
- Host: GitHub
- URL: https://github.com/adalfarus/argumint
- Owner: adalfarus
- License: lgpl-2.1
- Created: 2024-03-24T13:32:31.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2024-06-05T17:04:35.000Z (8 months ago)
- Last Synced: 2024-12-03T10:27:15.748Z (about 2 months ago)
- Language: Python
- Size: 37.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ArguMint
A fresh new way to handle cli
## How to use it
```python
from argumint import ArgStruct, ArguMint
from typing import Literal
import sysdef 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 = {'apt': {'build': {'file': {}, 'dir': {'main': {}, 'all': {}}}, 'help': {}}}
# Example usage
builder = ArgStruct()
builder.add_command("apt")
builder.add_nested_command("apt", "build", "file")builder.add_nested_command("apt.build", "dir", {'main': {}, 'all': {}})
# builder.add_subcommand("apt.build", "dir")
# builder.add_nested_command("apt.build.dir", "main")
# builder.add_nested_command("apt.build.dir", "all")builder.add_command("apt.help")
# builder.add_nested_command("apt", "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("apt.help", help_text)parser.add_endpoint("apt.build.file", build_file)
sys.argv[0] = "apt"
# Testing
# sys.argv = ["apt", "help"]
# sys.argv = ["apt", "build", "file", "./file.py", "--num=19"]
parser.parse_cli(sys, "native_light")
print(timer.end())
```