Metadata-Version: 2.1
Name: climatik
Version: 0.3.0
Summary: Create command line interface from function definitions.
Home-page: https://git.sr.ht/~fabrixxm/climatik
Author: Fabio Comuni
Author-email: fabrix.xm+pypi@gmail.com
License: GPLv3+
Platform: UNKNOWN
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: COPYING

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. If no type is defined, paramenter are handled as strings.

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 [`typing.Optional`](https://docs.python.org/3/library/typing.html#typing.Optional) type as hint with the parameter type, e.g. `Optional[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:Optional[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(prog:str=None, usage:str=None, description:str=None, **kwargs)

Run your application.

Builds the command line parse, with given arguments, and execute the requested 
function. It's a shorthand for

    parser = build_parser(prog, usage, description, **kwargs)
    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


