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

Requirements

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

  • above Python 3.9

Getting Started

To create our own command, just type following code:

@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.5.tar.gz (5.6 kB view hashes)

Uploaded Source

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