|
454 | 454 | (ansi-bold (ansi-fg :green "Clojure"))
|
455 | 455 | (ansi-fg :green "on nREPL port")
|
456 | 456 | (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))))) |
461 | 465 | ;; #_(apply println "Java flags: " (:java-args ctx))
|
462 | 466 | ;; (println "\nMiddleware: " )
|
463 | 467 | ;; (doseq [a (:middleware ctx)] (println "-" a))
|
|
492 | 496 | (recur))))
|
493 | 497 | proc))
|
494 | 498 |
|
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)))))) |
522 | 529 |
|
523 | 530 | (defn start-clojure-process [{:keys [options aliases nrepl-port] :as ctx}]
|
524 | 531 | (let [args (clojure-cli-args ctx)]
|
|
0 commit comments