Skip to main content

A typed command line parser

Project description

Run Run

A typed command line parser for Python.

Example

# main.py
import random
from runrun import Command
from runrun.models import Argument
from runrun.runner import Runner

class 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',
		value=1,
	)

	faces = Argument[int](
		name='faces',
		description='how many faces per dice',
		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!

python .\main.py --num 5 --faces 20

Or check the generated help command.

python .\main.py help
  Roll a dice

 USAGE 
  roll [arguments]

 ARGUMENTS 
  faces             --faces <int>                              | how many faces per dice
  num               --num <int>                                | Number of dice to roll

 COMMANDS 
  Help              help                                       | Show help about this command

The help command has it's own help docs !?

python .\main.py help help
  Show help about this command

 USAGE 
  roll help [arguments]

 ARGUMENTS 
  Filter            --filter <str>                             | 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 arguments

 COMMANDS 
  Help              help                                       | Show help about this command

Finally a help that can be filtered

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

runrun-0.0.1.tar.gz (15.7 kB view details)

Uploaded Source

Built Distribution

runrun-0.0.1-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

File details

Details for the file runrun-0.0.1.tar.gz.

File metadata

  • Download URL: runrun-0.0.1.tar.gz
  • Upload date:
  • Size: 15.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for runrun-0.0.1.tar.gz
Algorithm Hash digest
SHA256 360d67829ed2e0337af6cda50e2ea2421e0c44da3171f101fc186474cb4a15a5
MD5 1b4b3cc86aa5137fa0c652a39d40675b
BLAKE2b-256 c123e5e24ba6e7fd79735347e6ddcc7c78eb70c7f9fd26ba3c37f04bf88f9ca6

See more details on using hashes here.

File details

Details for the file runrun-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: runrun-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 12.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for runrun-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d1f115d8109cf33ff36677cf9ee10c10162a77b71c6f73415e905fcde0135d0d
MD5 6b001539c07a69278069670b2628dede
BLAKE2b-256 02c4adba280d344a9b103cd066d9e772d44c809773c35a752619b7e45fbc8a40

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page