Skip to content

Commit f73dcc3

Browse files
committed
Improve route listing
1 parent e505456 commit f73dcc3

File tree

1 file changed

+17
-33
lines changed

1 file changed

+17
-33
lines changed

src/k16/kl/commands/routes.clj

Lines changed: 17 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,17 @@
2828
"")
2929
branch (str border " " (get-tree-branch j (count routes)))
3030
path (str " @|bold,green " (or (:path-prefix route) "/") "|@")
31-
target (str " -> " (name (:service route)) "@|white @|@@|cyan " (name (:endpoint route)) "|@")]
31+
target-name (str "@|white [" (-> route :service name) "@" (-> route :endpoint-name name) "]|@")
32+
target (str " -> @|green " (get-in route [:endpoint :url]) "|@ " target-name)]
3233
(log/info (str branch path target)))))))
3334

3435
(defn- list-routes-table [routes]
35-
(pprint/print-table [:name :host :path-prefix :service :endpoint :enabled] routes))
36+
(pprint/print-table [:name :host :path-prefix :service :endpoint :url]
37+
(->> routes
38+
(map (fn [route]
39+
(-> route
40+
(assoc :endpoint (:endpoint-name route))
41+
(assoc :url (-> route :endpoint :url))))))))
3642

3743
(defn- list-routes [props]
3844
(let [module-name (prompt.config/get-module-name props)
@@ -43,12 +49,17 @@
4349
routes
4450
(->> (get-in module [:network :routes])
4551
(map (fn [[route-name route]]
46-
(let [service (get-in module [:network :services (:service route)])]
52+
(let [service (get-in module [:network :services (:service route)])
53+
endpoint-name (or (:endpoint route)
54+
(:default-endpoint service))
55+
endpoint (get-in service [:endpoints endpoint-name])]
4756
(merge route
4857
{:name (name route-name)
4958
:path-prefix (or (:path-prefix route) "/")
50-
:endpoint (or (:endpoint route)
51-
(:default-endpoint service))
59+
:endpoint-name endpoint-name
60+
:endpoint endpoint
61+
:url (or (:endpoint route)
62+
(:default-endpoint service))
5263
:enabled (get route :enabled true)}))))
5364
(sort (fn [a b]
5465
(let [a (count (:path-prefix a))
@@ -97,31 +108,4 @@
97108
:short 0
98109
:type :string}]
99110

100-
:runs apply-routes!}
101-
102-
#_#_#_{:command "configure"
103-
:description "Select which routes are enabled or disabled"
104-
105-
:opts [{:option "module"
106-
:short 0
107-
:type :string}]
108-
109-
:runs (fn [_])}
110-
111-
{:command "set-service"
112-
:description "Set the service for a route"
113-
114-
:opts [{:option "module"
115-
:short 0
116-
:type :string}]
117-
118-
:runs (fn [_])}
119-
120-
{:command "set-endpoint"
121-
:description "Set the endpoint for a route"
122-
123-
:opts [{:option "module"
124-
:short 0
125-
:type :string}]
126-
127-
:runs (fn [_])}]})
111+
:runs apply-routes!}]})

0 commit comments

Comments
 (0)