Skip to main content

Click Command Loader (CCL)

Click Command Loader

Click Command Loader (Referred as CCL) is an additional package for Click to load Click commands from a folder.

As such, by having the following folder structure:

my_project/
├─ commands/
│  ├─ create.py
│  ├─ delete.py
│  ├─ list.py
├─ __init__.py

The commands create, delete and list will be registered in your Click app!

Installation

I'm a package that is available on PyPi!

With Pip

pip install clickloader

With Poetry

poetry add clickloader

Example

Let's consider you have the following commands structure:

my_project/
├─ commands/
│  ├─ create.py
│  ├─ delete.py
│  ├─ list.py
├─ cli.py

Inside your cli.py, you should have your base logic for your CLI app. Originally, this is where all your commands would be registered, but CCL will help you leverage the work here.

Here's is what the content of the cli.py would be:

import click
import ccl
import pathlib


path_to_commands = pathlib.Path(__file__, "..", "commands")

my_cli = click.Group("MyCLI")
ccl.register_commands(my_cli, path_to_commands)

if __name__ == "__main__":
    my_cli()

And voilà! All commands inside your "commands" folder have been registered!

Behind the scene

When registering commands, CCL will do the following:

  1. List files and folder inside the given source.

  2. Iterate over directory, if a file is found, go to step 3, if a folder is found, go to step 2.1

    2.1. If folder, see if a __init__.py exist, if it exist, attempt to export a function that contains a click decorator (MUST BE A GROUP). If not found, create a click group, then continue to step 3 using the indicated group.

  3. If file, attempt to export a function that contains a click decorator (MUST BE A COMMAND), then add it to the given group.

  4. Continue until all files/folder have been scanned.

Release files for clickloader 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for clickloader 0.2.0
File Size Uploaded
clickloader-0.2.0.tar.gz 4.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for clickloader 0.2.0
File Interpreter ABI Platform
clickloader-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 9.1 kB

Release files / clickloader-0.2.0.tar.gz

Download URL clickloader-0.2.0.tar.gz
Size 4.2 kB
Tags Source
SHA-256 checksum
How to use checksums
ab2adedc698f253077e644de4146ef783eb21cd64abfaba31a1b182125577d49
BLAKE2b-256 checksum
How to use checksums
a8b2d015ee91e1d7cf88b1bc1717e6c13d8456572403b14f4436f77a739446c4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.6.1 CPython/3.10.12 Linux/6.2.0-1011-azure

Release files / clickloader-0.2.0-py3-none-any.whl

Download URL clickloader-0.2.0-py3-none-any.whl
Size 4.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
afe10548b98711d14e2283f3d4e4c188d7dff814c6ef08ba502ab60d5302360b
BLAKE2b-256 checksum
How to use checksums
a4c70598b0fb6d1a45abdd49799db1615f25576c12e151b96e6409937eea4237
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.6.1 CPython/3.10.12 Linux/6.2.0-1011-azure

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page