Skip to main content

Click Command Loader, permit to load Click command from a given folder.

Project description

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.

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

clickloader-0.1.2.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

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

clickloader-0.1.2-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file clickloader-0.1.2.tar.gz.

File metadata

  • Download URL: clickloader-0.1.2.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.10.6 Linux/5.15.0-1041-azure

File hashes

Hashes for clickloader-0.1.2.tar.gz
Algorithm Hash digest
SHA256 8568d2f3b6c52f6bc349e7070a8ec1bde8676422dfe70c2efb1db3c9f85d58f3
MD5 3ba11bf8499ec63651ab4e55f485258d
BLAKE2b-256 6c23962ab1a6fee58ece45b840f994f47682c8b8eaf5f18368b4a0e5b5a24ee2

See more details on using hashes here.

File details

Details for the file clickloader-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: clickloader-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.10.6 Linux/5.15.0-1041-azure

File hashes

Hashes for clickloader-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 070fc061e986ebc95d6faa6e2887b8debb62b90fa9903c92d869fef6e69a4afe
MD5 e1c2133e216a82d9636e7169a49c224b
BLAKE2b-256 68029c65988b93a485461f0842290d0895bd5637c83c921384fc1861ee23a14a

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