Skip to main content

Click group wrapper for loading click commands from separate files.

Project description

ClickD

Adds a click-based decorator that allows you to specify the directory with all the files being the subcommands/groups; and allows nesting the decorator--in the subdirectories' init-files--to traverse a directory tree for a quicker and cleaner cli-code layout.

Install

pip install clickd

Usage

Decorate the top-level--and all directory-modules' __init__ under--with the clickd decorator.

# <package-root-folder>/<cli-interface-top-level-folder>

./clickd/tests/cli  # <- this is the real test/example directory in this repo.
│   a.py
│   b.py
│   __init__.py
│
├───c
│   │   d.py
│   │   __init__.py
│   │
│   └───__pycache__
│           e.cpython-312.pyc
│           __init__.cpython-312.pyc
│
├───e
│   │   f.py
│   │   __init__.py
│   │
│   ├───g
│   │       j.py
│   │       __init__.py
│   │
│   └───h
│           k.py
│           __init__.py
│
└───__pycache__
        a.cpython-312.pyc
        b.cpython-312.pyc
        __init__.cpython-311.pyc
        __init__.cpython-312.pyc

The __init__.py files will contain @clickd(dirp=./clickd/tests/cli/<folder>); for e.g., h/__init__.py will have:

from clickd import clickd

@clickd(dpath="./clickd/tests/cli/e/h")
def h():
    pass

And all the init-files in ./clickd/tests/cli/e/h (and ./clickd/tests/cli/e, and ./clickd/tests/cli, for that matter) will have this set-up; every click.Group that I want to automatically load subcommands as individual files from.

The subcommands will, for e.g., look like this (in this case ./clickd/tests/cli/e/h/k.py):

import click

@click.command()
def k():
    print("k")

Click can be used interoperably; the only thing that won't work is the @clickd groups don't allow the use of .add_command(); I can use @click.group() as long as it is in a file found by the @clickd(dirpath=<path-to-folder-containing-file-with-group>) or it is chained by a regular instance of click.Group that eventually parents-back to the @clickd(), which is a click.MultiCommand subclass called ClickD.

I can use @click.command(cls=ClickD, dirp=<path>) above my group, instead--as a note.

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

clickd-0.1.1.tar.gz (15.0 kB view details)

Uploaded Source

Built Distribution

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

clickd-0.1.1-py3-none-any.whl (15.1 kB view details)

Uploaded Python 3

File details

Details for the file clickd-0.1.1.tar.gz.

File metadata

  • Download URL: clickd-0.1.1.tar.gz
  • Upload date:
  • Size: 15.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.4 Windows/11

File hashes

Hashes for clickd-0.1.1.tar.gz
Algorithm Hash digest
SHA256 951e9d1497c5cc5cd8b2b2638dcecc65943c3e39934e1e1d81192cc644d09760
MD5 841bf8140264ddd451ba87bf36369c07
BLAKE2b-256 75642956318dd9874b989eb8c4da602e08ac191dcb23e846c795eddf81bfcd10

See more details on using hashes here.

File details

Details for the file clickd-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: clickd-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 15.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.4 Windows/11

File hashes

Hashes for clickd-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a3da9cf04d364a6a198525da7e21cd58d933534b2b732786cde95d6304e091d7
MD5 601ed3f81b1f6a7fa1b83d3adf5c1ded
BLAKE2b-256 eb0465857a0faf77176ef6c91da196734b6dfca2fafa5da2ffc837da1efc690b

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