Skip to main content

Extension of `argparse` to provide fast and customizable argument parsing.

Project description

slap.core.cli

Extension of argparse to provide fast and customizable argument parsing.

Features

  • Minimal API; interact mostly argparse
  • Fast; because argparse is fast
  • Completion; built-in support

Usage

import argparse
from typing import Any, Optional

from slap.core.cli import CliApp, Command
from slap.core.cli.completion import CompletionCommand


class HelloCommand(Command):
    """ say hello to someone """

    def init_parser(self, parser: argparse.ArgumentParser) -> None:
        parser.add_argument("name")

    def execute(self, args: Any) -> Optional[int]:
        print(f"Hello, {args.name}!")


app = CliApp("minimal", "0.1.0")
app.add_command("hello", HelloCommand())
app.add_command("completion", CompletionCommand())
app.run()

Gives you the following CLI:

$ python examples/minimal.py
usage: minimal [-h] [-v] [--version] [{hello,completion}] ...

positional arguments:
  {hello,completion}  the subcommand to execute
  ...                 arguments for the subcommand

options:
  -h, --help          show this help message and exit
  -v, --verbose       increase the verbosity level
  --version           show program's version number and exit

subcommands:
  hello               say hello to someone
  completion          completion backend for bash

On Completion

You can run python examples/minimal.py completion --bash to get the code that should be run in your shell to enable completion features. However, you will need to make command available as a first-order command in your shell for completion to work (e.g. minimal instead of python examples/minimal.py).

Compatibility

Requires Python 3.6 or higher.

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

slap.core.cli-0.2.0.tar.gz (9.2 kB view details)

Uploaded Source

Built Distribution

slap.core.cli-0.2.0-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file slap.core.cli-0.2.0.tar.gz.

File metadata

  • Download URL: slap.core.cli-0.2.0.tar.gz
  • Upload date:
  • Size: 9.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.64.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for slap.core.cli-0.2.0.tar.gz
Algorithm Hash digest
SHA256 c81bf6347f669383e157cb7403aa9502b0f736a37b96b25ec76352d54f80bf3f
MD5 b16518a40b2e969f143f1074b5db5412
BLAKE2b-256 8a2515efcf31002b6a6eeee1f9f27975e9d1efc556af243ef1675676acc8f474

See more details on using hashes here.

File details

Details for the file slap.core.cli-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: slap.core.cli-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.64.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for slap.core.cli-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 37b0d9b3299de2b6119695c2695889fdea1e25c05f1f64cd7fc18842ac074db9
MD5 c8fdf14f8533529adf0578cefa0d4ca4
BLAKE2b-256 cc4fce7748d56d89bbf26dd8907f2c77aac7284124660f32941becc4130d18ec

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