Skip to content

Commit 0c8c519

Browse files
committed
Add two-arg run-process, print aliases
1 parent cf07a23 commit 0c8c519

File tree

2 files changed

+40
-34
lines changed

2 files changed

+40
-34
lines changed

CHANGELOG.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22

33
## Added
44

5-
## Fixed
6-
7-
## Changed
5+
- Print aliases being used
6+
- Add two-arg (uncurried) `run-process`
87

98
# 0.27.126-alpha (2024-02-26 / 5f25d2d)
109

src/lambdaisland/launchpad.clj

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -454,10 +454,14 @@
454454
(ansi-bold (ansi-fg :green "Clojure"))
455455
(ansi-fg :green "on nREPL port")
456456
(ansi-fg :magenta (:nrepl-port ctx)))
457-
(println (ansi-fg :green "Options:")
458-
(str/join ", " (map (comp (partial ansi-fg :magenta) name key) (filter (comp true? val) (:options ctx)))))
459-
;; (println "Aliases:")
460-
;; (doseq [a (:aliases ctx)] (println "-" a))
457+
(let [opts (filter (comp true? val) (:options ctx))
458+
aliases (:aliases ctx)]
459+
(when (seq opts)
460+
(println (ansi-fg :green "Options:")
461+
(str/join ", " (map (comp (partial ansi-fg :magenta) name key) opts))))
462+
(when (seq aliases)
463+
(println (ansi-fg :green "Aliases:")
464+
(str/join ", " (map (comp (partial ansi-fg :magenta) name) aliases)))))
461465
;; #_(apply println "Java flags: " (:java-args ctx))
462466
;; (println "\nMiddleware: " )
463467
;; (doseq [a (:middleware ctx)] (println "-" a))
@@ -492,33 +496,36 @@
492496
(recur))))
493497
proc))
494498

495-
(defn run-process [{:keys [cmd prefix working-dir
496-
background? timeout-ms check-exit-code? env
497-
color show-command?]
498-
:or {working-dir "."
499-
check-exit-code? true
500-
show-command? true}}]
501-
(fn [ctx]
502-
(let [working-dir (io/file working-dir)
503-
proc-builder (doto (ProcessBuilder. (map str cmd))
504-
(.directory working-dir))
505-
_ (.putAll (.environment proc-builder) (or env (:env ctx)))
506-
color (mod (hash (or prefix (first cmd))) 8)
507-
prefix (str "[" (ansi-fg (+ 30 color) (or prefix (first cmd))) "] ")
508-
process (pipe-process-output (.start proc-builder) prefix)
509-
ctx (update ctx :processes (fnil conj []) process)]
510-
(when show-command?
511-
(apply println (str prefix "$") (map shellquote cmd)))
512-
(if background?
513-
ctx
514-
(let [exit (if timeout-ms
515-
(.waitFor process timeout-ms TimeUnit/MILLISECONDS)
516-
(.waitFor process))]
517-
(when (and check-exit-code? (not= 0 exit))
518-
(do
519-
(println (str prefix) "Exited with non-zero exit code: " exit)
520-
(System/exit exit)))
521-
ctx)))))
499+
(defn run-process
500+
([ctx opts]
501+
((run-process opts) ctx))
502+
([{:keys [cmd prefix working-dir
503+
background? timeout-ms check-exit-code? env
504+
color show-command?]
505+
:or {working-dir "."
506+
check-exit-code? true
507+
show-command? true}}]
508+
(fn [ctx]
509+
(let [working-dir (io/file working-dir)
510+
proc-builder (doto (ProcessBuilder. (map str cmd))
511+
(.directory working-dir))
512+
_ (.putAll (.environment proc-builder) (or env (:env ctx)))
513+
color (mod (hash (or prefix (first cmd))) 8)
514+
prefix (str "[" (ansi-fg (+ 30 color) (or prefix (first cmd))) "] ")
515+
process (pipe-process-output (.start proc-builder) prefix)
516+
ctx (update ctx :processes (fnil conj []) process)]
517+
(when show-command?
518+
(apply println (str prefix "$") (map shellquote cmd)))
519+
(if background?
520+
ctx
521+
(let [exit (if timeout-ms
522+
(.waitFor process timeout-ms TimeUnit/MILLISECONDS)
523+
(.waitFor process))]
524+
(when (and check-exit-code? (not= 0 exit))
525+
(do
526+
(println (str prefix) "Exited with non-zero exit code: " exit)
527+
(System/exit exit)))
528+
ctx))))))
522529

523530
(defn start-clojure-process [{:keys [options aliases nrepl-port] :as ctx}]
524531
(let [args (clojure-cli-args ctx)]

0 commit comments

Comments
 (0)