Statikomand
Python static command parser, with command completion.
Subclasses argparse, but without connection to CLI. Only string to python objects.
Parses a raw string list into a structured object, and proposes completion for options, flags, ...
Getting Started
pip install statikomand
Basic Usage
from statikomand.komand_parser import KomandParser
# Example Usage
parser = KomandParser(prog="my-parser") # subclass of argparse.ArgumentParser
def pos1_completer(word, rank):
return [f"pos1 completer : {word}-{rank}"]
def pos2_completer(word, rank):
return [f"pos2 completer : {word}-{rank}"]
def opt1_completer(word, rank):
return [f"opt1 completer : {word}-{rank}"]
def opt2_completer(word, rank):
return [f"opt2 completer : {word}-{rank}"]
parser.add_argument("pos1", nargs=1, completer=pos1_completer) # give completer method, which is called when the parser is asked to complete the line
parser.add_argument("pos2", nargs=1, completer=pos2_completer)
parser.add_argument("--opt1", "-o1", nargs=2, completer=opt1_completer)
parser.add_argument("--opt2", "-o2", nargs=2, completer=opt2_completer)
arg_strings = shlex.split("argpos1 argpo")
print(parser.complete(arg_strings)) # ['pos2 completer : argpo-1']
arg_strings = shlex.split("argpos")
print(parser.complete(arg_strings)) # ['pos1 completer : argpos-1']
arg_strings = shlex.split("--")
print(
parser.complete(arg_strings)
) # ['--help', '--opt1', '--opt2'] - help flag is by default on all argparse.ArgumentParser
arg_strings = shlex.split("--op")
print(
parser.complete(arg_strings)
) # ['--opt1', '--opt2'] - help flag is by default on all argparse.ArgumentParser
arg_strings = shlex.split("argpos1 --opt1 argopt1 arg")
print(
parser.complete(arg_strings)
) # ['opt1 completer : arg-2'] - second argument of opt1 needs to be completed
arg_strings = shlex.split("argpos1 --opt1 argopt1 argopt2 arg")
print(
parser.complete(arg_strings)
) # ['pos2 completer : arg-1'] - completer of pos2
arg_strings = shlex.split("argpos1 --opt1 argopt1 argopt2 --o")
print(
parser.complete(arg_strings)
) # ['--opt2'] - completes flag name among the ones not already seen before
Completion detail
When calling add_argument method of KomandParser, you can add a completer method, which is a function that take a string and an int as argument, and returns a list of strings (proposition of completions).
The 'complete' method of the parser tries to complete the flag names, and calls the complete method of positional and / or flag arguments; according to the position of the last caracter.
Metadata
Release files for statikomand 0.2.0
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 |
|---|---|---|---|---|
| statikomand-0.2.0.tar.gz | 7.1 kB | Without provenance | Details for statikomand-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| statikomand-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for statikomand-0.2.0-py3-none-any.whl |
Total release size: 14.1 kB
Release files / statikomand-0.2.0.tar.gz
| Download URL | statikomand-0.2.0.tar.gz |
|---|---|
| Size | 7.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
637fbe5a86240bff650cf46319791df8595fb2a0ca0013f37514c4718aaf7853
|
|
BLAKE2b-256 checksum How to use checksums |
5b0c17da9617999ed3e548a80edb1edd517d01ba32a5ff51815fcca6fa47f610
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.3
|
Release files / statikomand-0.2.0-py3-none-any.whl
| Download URL | statikomand-0.2.0-py3-none-any.whl |
|---|---|
| Size | 7.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cb818e9364cac79cdcb2e2087cf840246c407cd7b037fc59daf99063d6b3f75f
|
|
BLAKE2b-256 checksum How to use checksums |
3eb289fa24d920efd8b357da77dde5031515528cee64c346699a79910bcf45fa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.3
|
Security for statikomand 0.2.0
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.