forked from luckyframework/lucky
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroutes.cr
69 lines (53 loc) · 1.39 KB
/
routes.cr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
require "lucky_task"
require "colorize"
require "shell-table"
class Routes < LuckyTask::Task
summary "Show all the routes for the app"
switch :with_params, "Include action params with each route", shortcut: "-p"
def help_message
<<-TEXT
#{summary}
Optionally, you can pass the --with-params flag (-p) to print out
the available params for each Action.
example: lucky routes --with-params
#{print_banner_message}
TEXT
end
def call
routes = [] of Array(String)
Lucky.router.routes.each do |method, path, action|
row = [] of String
row << method.to_s.upcase
row << path.colorize.green.to_s
row << action.name
routes << row
if with_params?
action.query_param_declarations.each do |param|
param_row = [] of String
param_row << " "
param_row << " #{dim_arrow} #{param}"
param_row << " "
routes << param_row
end
end
end
table = ShellTable.new(
labels: ["Verb", "URI", "Action"],
label_color: :white,
rows: routes
)
output.puts <<-TEXT
#{print_banner_message}
#{table}
TEXT
end
private def dim_arrow
"▸".colorize.dim
end
private def print_banner_message
<<-TEXT.colorize.dim
Routing documentation:
https://luckyframework.org/guides/http-and-routing/routing-and-params
TEXT
end
end