phoenix icon indicating copy to clipboard operation
phoenix copied to clipboard

Add --info option to mix phx.routes

Open fchabouis opened this issue 2 years ago • 5 comments

Hi!

I wrote some code allowing a user to locate in its code base the controller function called, given an URL. Following @josevalim suggestion to open a PR, here is a first step.

For the moment, I modified the phx.routes.ex file, allowing to pass a new option --info to the task. For example:

mix phx.routes --info http://localhost:4000/

Module: Elixir.RouteInfoTestWeb.PageController
Function: index

/home/francis/projects/phoenix/installer/route_info_test/lib/route_info_test_web/controllers/page_controller.ex:4

Before going further (documentation, tests, edge cases,...) I would appreciate a first feedback about this proposition to know if it seems interesting to the Phoenix team and if the code (location, method used to find the code location) looks valid to you.

To locate the code, I use:

  • Phoenix.Router.route_info to get the module and function called
  • module_info() to get the file where the module is defined
  • Code.fetch_docs to get the function definition line number in the file

Thank you

fchabouis avatar Apr 08 '22 09:04 fchabouis