Skip to main content

Simple CLI Parser with command chaining

Project description

CLI Parser

Simple Chained Command Parser

This tool will allow you to create a simple command hierarchy to execute from the command line.

Example

from cli_parser import command, CliParser, ParentCommand, CommandException

get = ParentCommand('get')

@command
def product(x, y):
    return x * y

@command
def sum(x, y):
    return x + y
    
get.add_sub_cmds(product, sum)

parser = CliParser([get])

while True:
    in_ = input("Enter command:\n==> ")
    
    try:
        response = parser.process_response(in_)
        print(response)
    except CommandException:
       pass

Execute your script from the command line:

Enter command:
==> get product 5 10
50

Enter command:
==> get sum 10 20
30

Enter command:
==> q

'Quitting Interpreter'

pypi: https://pypi.org/project/cli-parser/

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

cli_parser-0.1.3.tar.gz (11.2 kB view hashes)

Uploaded Source

Built Distribution

cli_parser-0.1.3-py3-none-any.whl (15.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