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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

climatik-0.3.0-py38-none-any.whl (16.5 kB view details)

Uploaded Python 3.8

climatik-0.3.0-2-py38-none-any.whl (16.7 kB view details)

Uploaded Python 3.8

File details

Details for the file climatik-0.3.0-py38-none-any.whl.

File metadata

  • Download URL: climatik-0.3.0-py38-none-any.whl
  • Upload date:
  • Size: 16.5 kB
  • Tags: Python 3.8
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.0 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

File hashes

Hashes for climatik-0.3.0-py38-none-any.whl
Algorithm Hash digest
SHA256 ab459acfc09ee96908eb0f48aa42dd834ecd468b6bf0106dbf3b658564f92d3a
MD5 bb452c6f446ce393a55b9fa906965452
BLAKE2b-256 f762369a462612f9dc8b5586b61c2734d11d9feca457609f1d119379caceaf82

See more details on using hashes here.

File details

Details for the file climatik-0.3.0-2-py38-none-any.whl.

File metadata

  • Download URL: climatik-0.3.0-2-py38-none-any.whl
  • Upload date:
  • Size: 16.7 kB
  • Tags: Python 3.8
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.5.0 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.1

File hashes

Hashes for climatik-0.3.0-2-py38-none-any.whl
Algorithm Hash digest
SHA256 1e7c46261d2cd5c5a82753677af7f015fb4a8a11aefcc877542852d3e9b507ef
MD5 167a50612b4626dcea693f6285abd630
BLAKE2b-256 4126fa6b9f74dab4d02ecde9252297bfdc9f2172639a229ceab1bf9ec75a2f0e

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