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 ofpython 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.1.tar.gz
(9.3 kB
view details)
Built Distribution
File details
Details for the file slap.core.cli-0.2.1.tar.gz
.
File metadata
- Download URL: slap.core.cli-0.2.1.tar.gz
- Upload date:
- Size: 9.3 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 54b91d06328d132be8985fd94691533fda424d6bb767b3ee5ba9744b85dac880 |
|
MD5 | 5718a051f3084e53a6a70a391c28ad59 |
|
BLAKE2b-256 | 7794862e51422af1426103e0bf3475c43084ac03e01cd7900171d5f016c99cdc |
File details
Details for the file slap.core.cli-0.2.1-py3-none-any.whl
.
File metadata
- Download URL: slap.core.cli-0.2.1-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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7cc3d6e4708849df54179abec4e7b3e5f545d93ec948884976443f258d72b3e8 |
|
MD5 | 0b24ce6632d0193e1b55d56a0ee43b50 |
|
BLAKE2b-256 | 9af7034de25ff7baa395e57089d72931fcf1fb8815634994e14e7a47a042cd65 |