Skip to main content

library to create a commandline application easily

Project description

Pillow logo PyCommandApp

library to create a commandline application easily

Index

Installation

python3 -m pip install commandapp
View on pypi.org

Usage

Code

from commandapp import CommandApp

app = CommandApp()


@app.register
def hello(name: str):
    r"""
    prints hello `name`
    """
    print("Hello {}".format(name))


@app.register(name="print")
def cmd_print(text: str):
    r"""
    print what he should say
    """
    print(text)


app.run()

Console

>> py myapp.py
usage: -c [-h] {hello,print} ...
>> py myapp.py -h
usage: -c [-h] {hello,print} ...

optional arguments:
  -h, --help     show this help message and exit

command:
  {hello,print}  available commands
    hello        prints hello `name`
    print        print what he should say
>> py myapp.py hello
usage: -c hello [-h] name
hello: error: the following arguments are required: name
>> py myapp.py hello "python"
Hello python
>> py myapp.py print "This package is awesome"
This package is awesome

Tips

Keyword-Parameter

Code

from commandapp import CommandApp

app = CommandApp()

@app.register
def a(param: str):
    print([param])

@app.register
def b(*, param: str):
    print([param])

app.run()

Console

>> py myapp.py a "Value"
["Value"]
>> py myapp.py b "Value"
b: error: the following arguments are required: --param
>> py myapp.py b --param "Value"
["Value"]

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

commandapp-0.2.1.tar.gz (3.0 kB view hashes)

Uploaded Source

Built Distribution

commandapp-0.2.1-py3-none-any.whl (2.7 kB view hashes)

Uploaded Python 3

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