Create command line interface from function definitions.
Project description
Create command line interface from function definitions.
Each function will be a subcommand of your application.
Climatik define a function decorator which parse function definition and build a subcommand command line parser.
Docs
def command(fnc:Callable)
Build subcommand from function
Subcommand name will be the function name and arguments are parsed to build the command line.
Each positional argument will be a positional paramenter.
Each optional argument will be an optional flag.
Type hints are used to covert types from command line string.
An argument with bool
type is converted to an optional flag parameter (with default sematic as "False")
To create an optional positional paramenter, use the Positional
custom type as hint, which optionally can get
a type too, eg Positional[str]
Function docstring is used to set command's help and description.
@command
def one(name, debug:bool, value="default", switchoff=True):
"First subcommand"
...
@command
def two(name:Positional[str] = None, long_param = None):
"Second subcommand"
...
gives:
$ script -h
usage: script [-h] {one,two} ...
positional arguments:
{one,two}
one First subcommand
two Second subcommand
optional arguments:
-h, --help show this help message and exit
$ script one -h
usage: script one [-h] [--debug] [--value VALUE] [--switchoff] name
First subcommand
positional arguments:
name
optional arguments:
-h, --help show this help message and exit
--debug
--value VALUE
--switchoff
$ script two -h
usage: script two [-h] [--long-param LONG_PARAM] [name]
Second subcommand
positional arguments:
name
optional arguments:
-h, --help show this help message and exit
--long-param LONG_PARAM
def run()
Run your application.
Builds the argparser and execute the requested function. It's a shorthand for
parser = build_parser()
execute(parser)
def execute(parser:argparse.ArgumentParser)
Execute command line from given parser
def get_parser(*args, **kwargs) -> argparse.ArgumentParser:
Build the command line parser
Arguments are passed to argparse.ArgumentParser
constructor
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
Built Distribution
File details
Details for the file climatik-0.1.0.tar.gz
.
File metadata
- Download URL: climatik-0.1.0.tar.gz
- Upload date:
- Size: 15.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.10.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb62466fe02e4e6c7d49731a84ae328ce57509d43422d57c6d8a2646bafc438c |
|
MD5 | 4c87a0b6e8a0694e1ed6ba22cb02f09e |
|
BLAKE2b-256 | 7c2b4a69aa4291db1544f9fe0ceab3c8670b8ef1dc546111e78c596ad9fed328 |
File details
Details for the file climatik-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: climatik-0.1.0-py3-none-any.whl
- Upload date:
- Size: 16.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.10.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7a284cd530870e47c2d92289bbd203edf34bdc9b3e0875c81d9f8b26452e475f |
|
MD5 | aa87749e7bb987ad6a521273488716dd |
|
BLAKE2b-256 | 339b2fff072472ebeeef5801595923513f8644cd660a5f3eb3486d3dab815e57 |