Skip to main content

def your CLIs

Project description

def your CLIs.

Use @subcommand on any function to add a subcommand to your cli. The function's arguments become the arguments to the subcommand. Uses argparse behind the scenes.

import defcli

@defcli.subcommand
def positional_integer(num: int):
    print(f"I like to add five: {num + 5}")

defcli.run()
$ python3 main.py positional_integer 7
I like to add five: 12

Or use named arguments.

import defcli

@defcli.subcommand
def named_string(*, name):
    print(f"Hello, {name}!")

defcli.run()
$ python3 main.py named_string --name Fred
Hello, Fred!

Named booleans are automatically converted to flags.

import defcli

@defcli.subcommand
def named_bool(has_something=False):
    if has_something:
        print("Got it!")
    else:
        print("We're empty-handed")

# Pass arguments to defcli.run instead of parsing sys.argv
defcli.run(["named_bool", "--has_something"])
$ python3 main.py
Got it!

Future

  • Allow @subcommand to take a parameter to allow the same program to define multiple CLI's.
  • Fix bugs (there are many...)

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

defcli-0.0.2.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

defcli-0.0.2-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file defcli-0.0.2.tar.gz.

File metadata

  • Download URL: defcli-0.0.2.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for defcli-0.0.2.tar.gz
Algorithm Hash digest
SHA256 bd49888ac992b449e3ae889c7cb84e97908e0f1350fa813f188a8a6d6aeb48c7
MD5 aaa4010a06b161ff457961d096cb742d
BLAKE2b-256 d97a6b2d9c1e996fd2f23fe7fd3b3d24e66b08ff7b2f18f653a17da703c23108

See more details on using hashes here.

File details

Details for the file defcli-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: defcli-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for defcli-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2739aa0cbaf01d0a048797c874e035fd5dcb71b6665f67ea0280ebfdab9335da
MD5 78bc33b033a08a355d3df6ba18c76633
BLAKE2b-256 396ab7495cffc97550be691715f137801fc5ce86188d6d18a708adcb387590fd

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