An open API service indexing awesome lists of open source software.

https://github.com/curskey/flask-cli-extend

Enhance Flask development workflow with powerful CLI commands for inspecting application.
https://github.com/curskey/flask-cli-extend

cli click command-line extension falsk-extension flask flask-plugins plugin

Last synced: 8 months ago
JSON representation

Enhance Flask development workflow with powerful CLI commands for inspecting application.

Awesome Lists containing this project

README

          

# Flask-CLI-Extend

[![Tests](https://github.com/curskey/flask-cli-extend/actions/workflows/tests.yaml/badge.svg)](https://github.com/curskey/flask-cli-extend/actions/workflows/tests.yaml)
[![Coverage](https://coveralls.io/repos/github/curskey/flask-cli-extend/badge.svg?branch=main)](https://coveralls.io/github/curskey/flask-cli-extend?branch=main)
[![PyPI version](https://badge.fury.io/py/flask-cli-extend.svg)](https://badge.fury.io/py/flask-cli-extend)

Enhance Flask development workflow with powerful CLI commands for inspecting application.

## Why this `Plugin`?

While Flask provides a robust framework for building web applications, the default CLI tools can sometimes be limited for developers who need to quickly inspect the structure and configuration of their application. This extension aims to fill that gap by providing clear, concise, and colorful outputs for commonly needed information, such as registered blueprints, URL routes, and application configurations. This helps to improve developer productivity and makes debugging and introspection easier.

## Installation

```bash
pip install flask-cli-extend
```

## Configuration

You can customize the behavior of this extension by setting the following variables in your Flask application's configuration file (e.g., `config.py`).

### `FLASK_CLI_EXTEND_TABLE_COLORS`

This variable allows you to customize the colors of the output tables.

**Type:** `list[str]`

**Default:** `["yellow", "cyan", "green", "blue", "magenta"]`

**Available colors:** `click` Supported color.

**Example:**

```python
FLASK_CLI_EXTEND_TABLE_COLORS = ["red", "blue"]
```

### `FLASK_CLI_EXTEND_SENSITIVE_CONFIG_KEYS`

This variable allows you to add to the list of sensitive keys that should be masked in the output of the `flask configs` command.

**Type:** `list[str]`

**Default:** `["SECRET", "KEY", "PASSWORD", "TOKEN"]`

**Example:**

```python
FLASK_CLI_EXTEND_SENSITIVE_CONFIG_KEYS = ["URI", "PWD"]
```

## Usage

Once installed, the new commands will be available through the `flask` command.

### `flask blueprints`

Displays information about registered Flask blueprints.

**Options:**

* `--sort`, `-s`: Sorts the blueprints by name.

**Output:**

The command outputs a table with the following columns:

* **Name**: The name of the blueprint.
* **Import Name**: The import name of the blueprint.
* **Relative Path**: The relative path to the blueprint's root.
* **URL Prefix**: The URL prefix for the blueprint.
* **Subdomain**: The subdomain for the blueprint (if any).

Example output:

```
Name Import Name Relative Path URL Prefix
-------- --------------- ----------------- ------------
main app.main src/app/main
api app.api src/app/api /api
```

### `flask routes`

Shows all registered routes with endpoints and methods.

**Options:**

* `--sort`, `-s` {endpoint,methods,domain,rule,match}: Method to sort routes by. 'match' is the order that Flask will match routes when dispatching a request.
* `--blueprint`, `-b` TEXT: Show the routes for the blueprint.
* `--all-methods`, `-A`: Show HEAD and OPTIONS methods.

**Output:**

The command outputs a table with the following columns:

* **Endpoint**: The endpoint name.
* **Methods**: The HTTP methods allowed for the route.
* **Rule**: The URL rule.
* **Host** / **Subdomain**: The host or subdomain for the route (if any).

Example output:

```
Endpoint Methods Rule Host
---------- --------- ------------ ------
main.index GET /
main.about GET /about
api.users GET, POST /api/users
```

### `flask configs`

Displays application configuration parameters.

**Options:**

* `--default`, `-d`: Show default config parameters.
* `--show-sensitive`, `-S`: Show sensitive values.
* `--diff`, `-D`: Show differences between current app and default config settings.
* `--namespace`, `-n` TEXT: Show config parameters that match the specified namespace/prefix.
* `--no-namespace`, `-N` TEXT: Show config parameters excluding those that match the specified namespace/prefix.

**Output:**

The command outputs a table with the following columns:

* **Key**: The configuration key.
* **Value**: The configuration value.

Sensitive values are masked by default.

Example output:

```
Key Value
---------------- ----------------------
DEBUG False
SECRET_KEY ab0*******
SQLALCHEMY_DB_URI postgresql://...
```

## Contributing

Contributions are welcome! Please open an issue or submit a pull request on GitHub.

## License

This project is licensed under the BSD License. See the `LICENSE` file for details.