Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add YAML support #27

Merged
merged 3 commits into from
Dec 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ format:
cat deps.edn | clojure -m portal.main edn
cat package.json | clojure -m portal.main json
cat transit.json | clojure -m portal.main transit
cat pipeline.yml | clojure -A:yaml -m portal.main yaml
```

I keep the following aliases handy for easier CLI use:
Expand All @@ -173,6 +174,7 @@ I keep the following aliases handy for easier CLI use:
alias edn='clojure -A:portal -m portal.main edn'
alias json='clojure -A:portal -m portal.main json'
alias transit='clojure -A:portal -m portal.main transit'
alias yaml='clojure -A:portal:yaml -m portal.main yaml'
```

and often use the `Copy as cURL` feature in the chrome network tab to do
Expand Down
4 changes: 3 additions & 1 deletion deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,6 @@
{:replace-deps
{antq/antq {:mvn/version "0.7.5"}
org.slf4j/slf4j-nop {:mvn/version "1.7.30"}}
:main-opts ["-m" "antq.core"]}}}
:main-opts ["-m" "antq.core"]}
:yaml
{:extra-deps {clj-commons/clj-yaml {:mvn/version "0.7.2"}}}}}
3 changes: 3 additions & 0 deletions src/portal/main.clj
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
(defn read-edn [reader]
(with-open [in (PushbackReader. reader)] (edn/read in)))

(defn read-yaml [] (require 'clj-yaml.core) (resolve 'clj-yaml.core/parse-string))

(defn -main [& args]
(let [[input-format] args
in (case input-format
"json" (-> System/in io/reader (json/parse-stream true))
"yaml" (-> System/in io/reader slurp ((read-yaml)))
"edn" (-> System/in io/reader read-edn)
"transit" (-> System/in t/json-stream->edn))]
(p/open)
Expand Down