Skip to main content

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(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

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

climatik-0.2.0.tar.gz (15.8 kB view details)

Uploaded Source

Built Distribution

climatik-0.2.0-py3-none-any.whl (16.4 kB view details)

Uploaded Python 3

File details

Details for the file climatik-0.2.0.tar.gz.

File metadata

  • Download URL: climatik-0.2.0.tar.gz
  • Upload date:
  • Size: 15.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for climatik-0.2.0.tar.gz
Algorithm Hash digest
SHA256 4575ec9c6ad0b4ea443219ce551f26ebd3f897c31a5178801f11353df0e1fc9d
MD5 ab8d993b247e949796af4394cdde442f
BLAKE2b-256 d2e9a061fdaab051ca0dfad6092c4b4697eb7e315b5360a8f109f81e60aea3bf

See more details on using hashes here.

File details

Details for the file climatik-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: climatik-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 16.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for climatik-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ab9d8bfc46a0ec0c79d59fe6a912aaf538b08a573542ea1feff0e198c60b0880
MD5 63818df28c8f1366cdaaa5d551043475
BLAKE2b-256 17277d6c11084272e09cb77d62a912d89111e31edd2c51d27442d5fb998a7af4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page