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.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

climaker-0.1.0-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

Details for the file climaker-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: climaker-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.0

File hashes

Hashes for climaker-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 936d92d2c510922eb1af1e53e740115a0a48c760675c445c9436126f6be5f96d
MD5 4a9aedef0e1b2a387cfd16ea2e72460b
BLAKE2b-256 92ea07df3220baf629d63ac11f6f534429ad503730018f1c47ab26cbe5465a9e

See more details on using hashes here.

Supported by

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