mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-07-25 02:19:12 -04:00
This is the suggested approach in the documentation [1] and using it makes it clearer what's going on and to add other commands with arguments, which we'll do in the next commit. [1]: https://flask.palletsprojects.com/en/2.0.x/cli/#custom-commands
16 lines
460 B
Python
16 lines
460 B
Python
import click
|
|
from flask import current_app
|
|
from flask.cli import with_appcontext
|
|
|
|
|
|
@click.command('list-routes')
|
|
@with_appcontext
|
|
def list_routes():
|
|
"""List URLs of all application routes."""
|
|
for rule in sorted(current_app.url_map.iter_rules(), key=lambda r: r.rule):
|
|
print("{:10} {}".format(", ".join(rule.methods - set(['OPTIONS', 'HEAD'])), rule.rule)) # noqa
|
|
|
|
|
|
def setup_commands(application):
|
|
application.cli.add_command(list_routes)
|