Skip to main content

Build a CLI parser with subcommands

Project description

CliMaker

Python package which allows to define a CLI argument parser (with subcommands) with a schema. The only dependency is the argparse library. Tested (a bit) with Python 3.6+

Please, create an issue if you have a bug-report or find this package needs an improvement. (It definitely needs an improvement.)

Installation

pip install climaker

Example

import sys
from climaker import Parser, Subcommands, Arguments, Arg

# Define commands structure
spec = Subcommands({
    'bake': Subcommands({
        'cake': Arguments([
            Arg('-s', '--size', type_=int, default=10),
            Arg('--color', default='pink'),
        ]),
        'cookie': Arguments([
            Arg('--kind', default='biscuit'),
        ]),
    }),
    'eat': Arguments([
        Arg('edible', default='cookie'),
    ])
})

# Create a parser
parser = Parser(spec)

# Parse arguments
action = parser.parse_arguments(sys.argv[1:])

print(action.command)
# ['bake', 'cake']

print(action.params)
# {'size': 10, 'color': 'pink'}

Project details


Download files

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

Files for climaker, version 0.1.0
Filename, size File type Python version Upload date Hashes
Filename, size climaker-0.1.0-py3-none-any.whl (3.7 kB) File type Wheel Python version py3 Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page