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.

Usage

import argparse
from typing import Any, Optional

from slap.core.cli import CliApp, Command


class HelloCommand(Command):
    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.run()

Gives you the following CLI:

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

positional arguments:
  {hello}        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

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.1.3.tar.gz (6.3 kB view hashes)

Uploaded Source

Built Distribution

slap.core.cli-0.1.3-py3-none-any.whl (7.5 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