 
   @moduledoc """
   Prints all routes for the default or a given router.
+  Can also locate the controller function behind a specified url.
 
-      $ mix phx.routes
-      $ mix phx.routes MyApp.AnotherRouter
+      $ mix phx.routes [ROUTER] [--info URL]
 
   The default router is inflected from the application
   name unless a configuration named `:namespace`

  defp app_mod(base, name), do: Module.concat([base, name])

  defp web_mod(base, name), do: Module.concat(["#{base}Web", name])
end

    Mix.Task.run("compile", args)
    Mix.Task.reenable("phx.routes")

    {opts, args, _} =
      OptionParser.parse(args, switches: [endpoint: :string, router: :string, info: :string])

    {router, endpoint} =
      case args do
        {opts, [passed_router], _} -> {passed_router, opts[:endpoint]}
        {opts, [], _} -> {router(opts[:router], base), endpoint(opts[:endpoint], base)}
      end

    case Keyword.fetch(opts, :info) do
      {:ok, url} ->
        get_url_info(url, {router, opts})

      :error ->
        router
        |> ConsoleFormatter.format(endpoint)
        |> Mix.shell().info()
    end
  end

  def get_url_info(url, {router_mod, _opts}) do
    %{path: path} = URI.parse(url)

    meta = Phoenix.Router.route_info(router_mod, "GET", path, "")
    %{plug: plug, plug_opts: plug_opts} = meta

    {module, func_name} =
      if log_mod = meta[:log_module] do
        {log_mod, meta[:log_function]}
      else
        {plug, plug_opts}
      end

    Mix.shell().info("Module: #{inspect(module)}")
    if func_name, do: Mix.shell().info("Function: #{inspect(func_name)}")

    file_path = get_file_path(module)

    if line = get_line_number(module, func_name) do
      Mix.shell().info("#{file_path}:#{line}")
    else
      Mix.shell().info("#{file_path}")
    end
  end

