Skip to content

Commit

Permalink
Improve route listing
Browse files Browse the repository at this point in the history
  • Loading branch information
julienvincent committed Nov 21, 2023
1 parent e505456 commit f73dcc3
Showing 1 changed file with 17 additions and 33 deletions.
50 changes: 17 additions & 33 deletions src/k16/kl/commands/routes.clj
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,17 @@
"")
branch (str border " " (get-tree-branch j (count routes)))
path (str " @|bold,green " (or (:path-prefix route) "/") "|@")
target (str " -> " (name (:service route)) "@|white @|@@|cyan " (name (:endpoint route)) "|@")]
target-name (str "@|white [" (-> route :service name) "@" (-> route :endpoint-name name) "]|@")
target (str " -> @|green " (get-in route [:endpoint :url]) "|@ " target-name)]
(log/info (str branch path target)))))))

(defn- list-routes-table [routes]
(pprint/print-table [:name :host :path-prefix :service :endpoint :enabled] routes))
(pprint/print-table [:name :host :path-prefix :service :endpoint :url]
(->> routes
(map (fn [route]
(-> route
(assoc :endpoint (:endpoint-name route))
(assoc :url (-> route :endpoint :url))))))))

(defn- list-routes [props]
(let [module-name (prompt.config/get-module-name props)
Expand All @@ -43,12 +49,17 @@
routes
(->> (get-in module [:network :routes])
(map (fn [[route-name route]]
(let [service (get-in module [:network :services (:service route)])]
(let [service (get-in module [:network :services (:service route)])
endpoint-name (or (:endpoint route)
(:default-endpoint service))
endpoint (get-in service [:endpoints endpoint-name])]
(merge route
{:name (name route-name)
:path-prefix (or (:path-prefix route) "/")
:endpoint (or (:endpoint route)
(:default-endpoint service))
:endpoint-name endpoint-name
:endpoint endpoint
:url (or (:endpoint route)
(:default-endpoint service))
:enabled (get route :enabled true)}))))
(sort (fn [a b]
(let [a (count (:path-prefix a))
Expand Down Expand Up @@ -97,31 +108,4 @@
:short 0
:type :string}]

:runs apply-routes!}

#_#_#_{:command "configure"
:description "Select which routes are enabled or disabled"

:opts [{:option "module"
:short 0
:type :string}]

:runs (fn [_])}

{:command "set-service"
:description "Set the service for a route"

:opts [{:option "module"
:short 0
:type :string}]

:runs (fn [_])}

{:command "set-endpoint"
:description "Set the endpoint for a route"

:opts [{:option "module"
:short 0
:type :string}]

:runs (fn [_])}]})
:runs apply-routes!}]})

0 comments on commit f73dcc3

Please sign in to comment.