python-restx / flask-restx

Fork of Flask-RESTPlus: Fully featured framework for fast, easy and documented API development with Flask
https://flask-restx.readthedocs.io/en/latest/
Other
2.16k stars 335 forks source link

Is there a way to register commands with Namespaces? #469

Open spitfiredd opened 2 years ago

spitfiredd commented 2 years ago

Ask a question I would like to register a command with a Namespace similarly to how Flask does it

For example,

import click
from ..views import api

@api.cli.command("setup")
@click.argument("name")
def create(name):
    return f"Successfully created {name}"

and from my .view.py

from flask_restx import Namespace

api = Namespace("search", description="Search data with Elasticsearch.")

Running flask search create alice returns Error: No such command 'search'.; similarly running flask --help doesn't like the command in the Commands section.

Additional context N/A

spitfiredd commented 2 years ago

I can just create a Blueprint for /api/search/cli; I don't need to hook into the Namespace object.