slap.core.cli
Extension of argparse to provide fast and customizable argument parsing.
Features
- Minimal API; interact mostly with
argparseor type hints - Fast; because
argparseis fast - Completion; built-in support
Usage (Command API)
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 --bashto 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.minimalinstead ofpython examples/minimal.py).
Usage (Typed API)
from slap.core.cli.typed import Argument, Option, TypedArgsBase, subcommand
from typing import Annotated
class SayHelloArgs(TypedArgsBase):
name: Annotated[str, Argument()]
greeting: str
version: Annotated[None, Option(version="1.0.0", short_name="V")]
args = SayHelloArgs.parse()
print(args)
Gives you the following CLI:
usage: test.py [-h] [--greeting GREETING] [--version] name
positional arguments:
name
options:
-h, --help show this help message and exit
--greeting GREETING
--version, -V show program's version number and exit
And running it gives:
$ python test.py John --greeting Hello
SayHelloArgs(name='John', greeting='Hello', version=None)
Note: Completion is currently not supported for the typed API.
Compatibility
Requires Python 3.7 or higher.
Metadata
Release files for slap.core.cli 0.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| slap.core.cli-0.3.1.tar.gz | 12.6 kB | Without provenance | Details for slap.core.cli-0.3.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| slap.core.cli-0.3.1-py3-none-any.whl | Python 3 | none | any | Details for slap.core.cli-0.3.1-py3-none-any.whl |
Total release size: 26.5 kB
Release files / slap.core.cli-0.3.1.tar.gz
| Download URL | slap.core.cli-0.3.1.tar.gz |
|---|---|
| Size | 12.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fb31fd6b17250ac8fdd89cfa0c9522bb76c8ad4f512b4858eb0b69c176b9cca9
|
|
BLAKE2b-256 checksum How to use checksums |
d12f5ddc608714cc3ffadec02ac8d31dbec29cf42847a7baf0d8d50e9937fcb5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Release files / slap.core.cli-0.3.1-py3-none-any.whl
| Download URL | slap.core.cli-0.3.1-py3-none-any.whl |
|---|---|
| Size | 13.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
62a6029d1562d66099c11f5d3cf243d28d629dc92a49aedff3a87cc6bd9e05e9
|
|
BLAKE2b-256 checksum How to use checksums |
b51c668e74f923149da18b914913ce3bc5c0c5fd99cf7a4a48c272ec352bbf3a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Security for slap.core.cli 0.3.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.