-
-
Notifications
You must be signed in to change notification settings - Fork 81
/
main.clj
33 lines (28 loc) · 1.11 KB
/
main.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
(ns portal.main
(:require [clojure.edn :as edn]
[clojure.java.io :as io]
[portal.api :as p])
(:import [java.io PushbackReader]))
(defn- lazy-fn [symbol]
(fn [& args] (apply (requiring-resolve symbol) args)))
(def ^:private read-json (lazy-fn 'portal.runtime.json/read-stream))
(def ^:private read-yaml (lazy-fn 'clj-yaml.core/parse-string))
(def ^:private transit-read (lazy-fn 'cognitect.transit/read))
(def ^:private transit-reader (lazy-fn 'cognitect.transit/reader))
(defn- read-transit [in]
(transit-read (transit-reader in :json)))
(defn- read-edn [reader]
(with-open [in (PushbackReader. reader)] (edn/read in)))
(defn -main [& args]
(let [[input-format] args
in (case input-format
"json" (-> System/in io/reader read-json)
"yaml" (-> System/in io/reader slurp read-yaml)
"edn" (-> System/in io/reader read-edn)
"transit" (-> System/in read-transit))]
(reset! (p/open) in)
(.addShutdownHook
(Runtime/getRuntime)
(Thread. #(p/close)))
(println "Press CTRL+C to exit")
@(promise)))