From 26460945a42b7dc0002166c6d7aaee05922293df Mon Sep 17 00:00:00 2001 From: Niko Lubbe Date: Wed, 24 Jul 2024 11:42:24 +0200 Subject: [PATCH] add output flag for services --- src/k16/kl/commands/services.clj | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/k16/kl/commands/services.clj b/src/k16/kl/commands/services.clj index 30a763a..b2cf88d 100644 --- a/src/k16/kl/commands/services.clj +++ b/src/k16/kl/commands/services.clj @@ -57,7 +57,14 @@ (log/info (str "@|green Service default-endpoint has been updated |@")))) -(defn- list-services [props] +(defn- list-service-list [services] + (doseq [service services] + (println (:name service)))) + +(defn- list-service-table [services] + (pprint/print-table [:name :default-endpoint] services)) + +(defn list-services [props] (let [module-name (prompt.config/get-module-name props) {:keys [modules]} (api.resolver/pull! module-name {}) @@ -67,7 +74,9 @@ (map (fn [[service-name service]] (merge service {:name (name service-name)}))))] - (pprint/print-table [:name :default-endpoint] services))) + (case (:output props) + "names" (list-service-list services) + "table" (list-service-table services)))) (def cmd {:command "services" @@ -76,7 +85,11 @@ :subcommands [{:command "list" :description "List all services" - :opts [{:option "module" + :opts [{:option "output" + :short "o" + :default "table" + :type :string}, + {:option "module" :short 0 :type :string}] @@ -86,13 +99,13 @@ :description "Set the default endpoint for a service" :opts [{:option "module" - :short 0 + :short "m" :type :string} {:option "service" - :short 1 + :short 0 :type :string} {:option "endpoint" - :short 2 + :short 1 :type :string}] :runs set-default-service-endpoint!}]})