Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/apollo-roboto/python-runrun
A typed command line parser for Python
https://github.com/apollo-roboto/python-runrun
cli library parser python typed
Last synced: 3 months ago
JSON representation
A typed command line parser for Python
- Host: GitHub
- URL: https://github.com/apollo-roboto/python-runrun
- Owner: Apollo-Roboto
- License: mit
- Created: 2023-08-13T16:57:39.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-06-17T02:08:38.000Z (6 months ago)
- Last Synced: 2024-09-18T10:54:15.313Z (3 months ago)
- Topics: cli, library, parser, python, typed
- Language: Python
- Homepage: https://pypi.org/project/runrun/
- Size: 212 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# RunRun
![PyPI Version](https://img.shields.io/pypi/v/runrun.svg)
![PyPI Python Version](https://img.shields.io/pypi/pyversions/runrun.svg?logo=python&logoColor=gold)
![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)
![License MIT](https://img.shields.io/pypi/l/runrun)A typed command line parser for Python.
## Example
```py
# main.py
import random
from runrun import Command
from runrun.models import Argument
from runrun.runner import Runnerclass RollCommand(Command):
def __init__(self):
super().__init__(
name="roll",
description="Roll a dice",
)num_of_dice = Argument(
int,
name="num",
description="Number of dice to roll",
default_value=1,
)faces = Argument(
int,
name="faces",
description="how many faces per dice",
default_value=6,
)def run(self):
total = 0
for _ in range(self.num_of_dice.value):
total += random.randint(1, self.faces.value)print(f"🎲 {total}")
Runner(RollCommand()).run()
```
Run it!
```powershell
python .\main.py --num 5 --faces 20
```Or check the generated help command.
```powershell
python .\main.py help
``````txt
Roll a dice
USAGE
roll [arguments]ARGUMENTS
faces --faces | how many faces per dice
num --num | Number of dice to rollCOMMANDS
Help help | Show help about this command```
The help command has it's own help docs !?
```powershell
python .\main.py help help
``````txt
Show help about this command
USAGE
roll help [arguments]ARGUMENTS
Filter --filter | Filter the help results, this can help to find what you are looking for
Output Format --format {STD, JSON} | The output format of the command details
Required Only --required-only [true|false] | Only show required argumentsCOMMANDS
Help help | Show help about this command
```*Finally a help that can be filtered*