Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add routes command to flask cli #2092

Closed
wants to merge 6 commits into from
Closed

Add routes command to flask cli #2092

wants to merge 6 commits into from

Conversation

willsoto
Copy link

@willsoto willsoto commented Nov 20, 2016

Running flask routes will list all registered routes for a given app, sorted by endpoint

Inspired by mix phoenix.routes, this will display a list of all registered routes in an application. This is basically #1446, but I have updated it and made it "dumber".

NB: I know that the other PR is old and there doesn't seem to be much enthusiasm for it, but I do think this is useful to have to get a high level overview of application routes, especially if they are being generated programmatically.

Example output:

$ flask routes
api.me                    GET              /api/users/me/
api.users                 GET              /api/users/
                          POST             /api/users/
                          PUT, DELETE, GET /api/users/<pk>
api.users_schema          GET              /api/users/schema/
auth_blueprint.authorized GET              /login/authorized
auth_blueprint.do_login   GET              /do-login
auth_blueprint.login      GET              /login
auth_blueprint.logout     GET              /logout
auth_blueprint.lr_test    GET              /lr
static                    GET              /static/<path:filename>

Running `flask routes` will list all registered routes for a given app, sorted by endpoint

Signed-off-by: Will Soto <will.soto9@gmail.com>
flask/cli.py Outdated
sorted_rules = sorted(app.url_map.iter_rules(), key=lambda rule: rule.endpoint)

for rule in sorted_rules:
methods = ', '.join(rule.methods.difference(ignored_methods))

This comment was marked as off-topic.

Signed-off-by: Will Soto <will.soto9@gmail.com>
output = [line.strip() for line in result.output.split('\n')]

assert result.exit_code == 0
assert output[0] == 'routes_blueprint.posts_routes PUT, DELETE, GET /posts/<post_id>'

This comment was marked as off-topic.


assert result.exit_code == 0
assert output[0] == 'routes_blueprint.posts_routes PUT, DELETE, GET /posts/<post_id>'
assert output[1] == 'routes_blueprint.user_id_route DELETE, GET /users/<user_id>'

This comment was marked as off-topic.

Signed-off-by: Will Soto <will.soto9@gmail.com>
flask/cli.py Outdated
app = _app_ctx_stack.top.app
routes = []
ignored_methods = set(['HEAD', 'OPTIONS'])
sorted_rules = sorted(app.url_map.iter_rules(), key=lambda rule: rule.endpoint)

This comment was marked as off-topic.

Signed-off-by: Will Soto <will.soto9@gmail.com>
@willsoto
Copy link
Author

willsoto commented Nov 20, 2016

@ThiefMaster Thanks for the feedback. I've made all the changes you requested.

@davidism davidism added the cli label Apr 19, 2017
@davidism davidism mentioned this pull request Apr 26, 2017
@davidism
Copy link
Member

Thanks for doing this. I started working on yours then decided I liked the output in #1446 better, so I reworked it with some of your ideas in #2259.

@davidism davidism closed this Apr 26, 2017
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants