Skip to main content

functional-oriented cli decorator.

Project description

dcli

cicd

dcli is a nested functional-oriented cli (command line interface) python module. dcli does not require any other third-party module, it just wraps and encapsolutes argparse in a decorator, i.e. @dcli.command().

Getting Started

Before installing, see Requirements to check the dependencies.

See Installation to install dcli to your local environment and Usage for more information about how to use.

Requirements

While dcli does not require any third-party, it requires run in Python with specific versions.

  • above Python 3.9

Installation

Only one step to install dcli:

$ python3 -m pip install decorator-cli

# pip list to check installation
$ python3 -m pip list

Package       Version
------------- ---------
decorator-cli <version>

Usage

To create our own command, just type following code:

import dcli
...

@dcli.command(
    "MyCommand",
    dcli.arg(...),
    dcli.arg(...),
    ...
)
def MyCommand(namespace):
  ...

...
# call the command function directly to parse the arguments from program.
MyCommand()

namespace which is of type argparse.Namespace will be passed from ArgumentParser.parse_args(). We can directly call MyCommand() without any parameters to parse the program arguments and then the original function MyCommand(namespace) will be invoked once parse_args() done. For advanced usage, it is possible to pass parameter args into MyCommand() to parse custom arguments, e.g.

MyCommand('--baz')
MyCommand(['-x', 'X'])
MyCommand(['--foo', 'bar'])

dcli also support subcommand:

@dcli.command(
    "COMMAND_NAME",
    dcli.arg(...),
    dcli.arg(...),
    ...,
    parent=MyCommand
)
def SubCommand(namespace):
  ...

MyCommand()

The above code will make SubCommand be a subcommand in MyCommand and named in COMMAND_NAME. By calling MyCommand(["COMMAND_NAME"]), we can easily trigger SubCommand(namespace) and do what we want.

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

decorator-cli-0.1.7.tar.gz (6.2 kB view details)

Uploaded Source

File details

Details for the file decorator-cli-0.1.7.tar.gz.

File metadata

  • Download URL: decorator-cli-0.1.7.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.2

File hashes

Hashes for decorator-cli-0.1.7.tar.gz
Algorithm Hash digest
SHA256 50ac36b16c23b1c034d994636a6dd7d9d8c897565db540f3672aa2abfb2e15fb
MD5 6ec5c93979f20d0b567d797c706c82b1
BLAKE2b-256 60c565723c9cf20ac6b15f0cb4c1e503e4e3ae34d27e69a0e3a0ae155c3bf5ca

See more details on using hashes here.

Supported by

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