This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-12-07
Channels
- # adventofcode (114)
- # announcements (3)
- # aws (5)
- # babashka (62)
- # beginners (111)
- # calva (4)
- # cider (20)
- # clara (5)
- # clj-kondo (1)
- # cljs-dev (9)
- # clojure (255)
- # clojure-europe (75)
- # clojure-italy (10)
- # clojure-nl (3)
- # clojure-norway (5)
- # clojure-uk (6)
- # clojuredesign-podcast (5)
- # clojurescript (34)
- # community-development (28)
- # conjure (1)
- # cursive (3)
- # data-science (1)
- # datavis (1)
- # datomic (4)
- # figwheel-main (1)
- # fulcro (14)
- # graalvm (1)
- # graphql (8)
- # integrant (4)
- # introduce-yourself (2)
- # jobs (2)
- # juxt (4)
- # kaocha (2)
- # malli (6)
- # membrane-term (53)
- # mount (2)
- # nextjournal (2)
- # off-topic (27)
- # pathom (11)
- # polylith (3)
- # portal (11)
- # reagent (4)
- # reitit (4)
- # remote-jobs (1)
- # reveal (14)
- # shadow-cljs (22)
- # tools-deps (24)
- # vim (6)
- # xtdb (19)
anybody have experience using mount with cli-matic? I'm passing mount/start-with-args
into a subcommand's :runs
attribute, and while the subcommand works, my program exits immediately, which is bad since I want an http server to run. not quite sure what i'm doing wrong
couldn't get to the bottom of this so using a workaround for now--leaving here for posterity
(defn stop-app []
(doseq [component (:stopped (mount/stop))]
(log/info component "stopped"))
(shutdown-agents))
(def cli-config
{:app '...
:global-opts []
:commands [{:command "run" :short "r"
:description ["Start the web app and begin listening for requests."]
:opts [{:option "port" :short "p" :as "port for HTTP server" :type :int}]
:runs mount/start-with-args
:on-shutdown stop-app}]})
(defn run-cmd
"like cli-matic's run-cmd, but doesn't exit at the end"
[args supplied-config]
(let [config (U2/cfg-v2 supplied-config)
{:keys [help stderr subcmd retval] :as result} (run-cmd* config args)]
; prints the error message, if present
(when (seq stderr)
(U/printErr ["** ERROR: **" stderr "" ""]))
; prints help
(cond
(= :HELP-GLOBAL help)
(let [helpFn (H/getGlobalHelperFn config subcmd)]
(U/printErr (helpFn config subcmd)))
(= :HELP-SUBCMD help)
(let [helpFn (H/getSubcommandHelperFn config subcmd)]
(U/printErr (helpFn config subcmd))))
;; For some reason, the run subcommand exits immediately when combined with cli-matic. Use this as a workaround.
(if (#{"run" "r"} (first args))
(log/info "Started server successfully")
(P/exit-script retval))))
(defn start-app [args]
(run-cmd args cli-config))
(defn -main [& args]
(start-app args))