More Click
More Click (more-click) is a Python library, currently at version 0.1.3, that provides implementations of common Command Line Interface (CLI) patterns built on top of the popular Click framework. It offers pre-defined options, web application integration utilities, and other conveniences to reduce boilerplate when developing Click-based CLIs. The library is actively maintained, with a focus on enhancing existing Click applications.
Common errors
-
ModuleNotFoundError: No module named 'more-click'
cause Attempting to import the library using its PyPI package name (with a hyphen) instead of its module name (with an underscore).fixChange your import statement from `import more-click` to `import more_click` or `from more_click import ...`. -
AttributeError: 'NoneType' object has no attribute 'run' (when using make_web_command)
cause The `make_web_command` utility expects a string pointing to a valid Flask application instance (e.g., 'my_package.wsgi:app'). If the specified path is incorrect or the app cannot be loaded, `run_app` will receive a `None` object.fixVerify that the string passed to `make_web_command('your_module:your_app_instance')` correctly points to your Flask application object. Ensure `your_module.py` and `your_app_instance` exist and are accessible.
Warnings
- gotcha When importing, use `more_click` (with an underscore) instead of `more-click` (with a hyphen). Python modules use underscores in their names, while package distribution names on PyPI often use hyphens.
- gotcha Do not confuse `more-click` with `rich-click`. While both build on Click, `more-click` provides common CLI patterns and utilities, whereas `rich-click` focuses specifically on enhancing the visual output and formatting of Click's help messages using the `rich` library.
- gotcha `more-click` is a collection of utilities and decorators that *extend* Click. It is not a standalone CLI framework and requires `click` to be installed and used as the underlying base for your commands.
Install
-
pip install more-click
Imports
- verbose_option
from more_click import verbose_option
- make_web_command
from more_click import make_web_command
- host_option
from more_click import host_option
- port_option
from more_click import port_option
- run_app
from more_click import run_app
Quickstart
import click
from more_click import make_web_command, verbose_option
# Example of a simple web command using more-click's utility
web_command = make_web_command('my_package.wsgi:app') # Replace 'my_package.wsgi:app' with your actual Flask app import path
@click.group()
def cli():
pass
@cli.command()
@verbose_option
@click.option('--custom-flag', is_flag=True, help='A custom flag.')
def my_tool(verbose: bool, custom_flag: bool):
"""A command demonstrating more-click options and custom logic."""
if verbose:
click.echo("Verbose mode enabled.")
if custom_flag:
click.echo("Custom flag enabled.")
click.echo("Running my_tool.")
cli.add_command(web_command, name='web') # Add the web command to your CLI group
if __name__ == '__main__':
# To run the web command: python your_cli.py web --host 0.0.0.0 --port 8000
# To run my_tool: python your_cli.py my-tool -v --custom-flag
cli()