parent
4d0b9aef42
commit
697360a265
11 changed files with 125 additions and 101 deletions
|
|
@ -136,6 +136,7 @@ explicitly.
|
|||
it is a function.
|
||||
- [`me.raynes.conch.low-level`](https://github.com/clj-commons/conch#low-level-usage)
|
||||
aliased as `conch`
|
||||
- [`clojure.tools.cli`](https://github.com/clojure/tools.cli) aliased as `tools.cli`
|
||||
|
||||
From Java the following is available:
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,8 @@
|
|||
:source-paths ["src" "sci/src" "sci/inlined"]
|
||||
:resource-paths ["resources" "sci/resources"]
|
||||
:dependencies [[org.clojure/clojure "1.10.1"]
|
||||
[org.clojure/core.async "0.4.500"]]
|
||||
[org.clojure/core.async "0.4.500"]
|
||||
[org.clojure/tools.cli "0.4.2"]]
|
||||
:profiles {:test {:dependencies [[clj-commons/conch "0.9.2"]]}
|
||||
:uberjar {:global-vars {*assert* false}
|
||||
:jvm-opts ["-Dclojure.compiler.direct-linking=true"
|
||||
|
|
|
|||
2
sci
2
sci
|
|
@ -1 +1 @@
|
|||
Subproject commit 7343d3912c4a486211200f2e81297ad4ef525647
|
||||
Subproject commit d4a893fa5d3a48de9779ac52e1ea8f927278e8d2
|
||||
|
|
@ -6,63 +6,63 @@
|
|||
[& body]
|
||||
`(~'async/thread-call (fn [] ~@body)))
|
||||
|
||||
(def async-bindings
|
||||
{'async/<!! async/<!!
|
||||
'async/>!! async/>!!
|
||||
'async/admix async/admix
|
||||
'async/alts! async/alts!
|
||||
'async/alts!! async/alts!!
|
||||
'async/buffer async/buffer
|
||||
'async/chan async/chan
|
||||
'async/close! async/close!
|
||||
'async/do-alt async/do-alt
|
||||
'async/do-alts async/do-alts
|
||||
'async/dropping-buffer async/dropping-buffer
|
||||
'async/filter< async/filter<
|
||||
'async/filter> async/filter>
|
||||
'async/into async/into
|
||||
'async/map async/map
|
||||
'async/map< async/map<
|
||||
'async/map> async/map>
|
||||
'async/mapcat< async/mapcat<
|
||||
'async/mapcat> async/mapcat>
|
||||
'async/merge async/merge
|
||||
'async/mix async/mix
|
||||
'async/mult async/mult
|
||||
'async/offer! async/offer!
|
||||
'async/onto-chan async/onto-chan
|
||||
'async/partition async/partition
|
||||
'async/partition-by async/partition-by
|
||||
'async/pipe async/pipe
|
||||
'async/pipeline async/pipeline
|
||||
'async/pipeline-async async/pipeline-async
|
||||
'async/pipeline-blocking async/pipeline-blocking
|
||||
'async/poll! async/poll!
|
||||
'async/promise-chan async/promise-chan
|
||||
'async/pub async/pub
|
||||
'async/put! async/put!
|
||||
'async/reduce async/reduce
|
||||
'async/remove< async/remove<
|
||||
'async/remove> async/remove>
|
||||
'async/sliding-buffer async/sliding-buffer
|
||||
'async/solo-mode async/solo-mode
|
||||
'async/split async/split
|
||||
'async/sub async/sub
|
||||
'async/take async/take
|
||||
'async/take! async/take!
|
||||
'async/tap async/tap
|
||||
'async/thread (with-meta thread {:sci/macro true})
|
||||
'async/thread-call async/thread-call
|
||||
'async/timeout async/timeout
|
||||
'async/to-chan async/to-chan
|
||||
'async/toggle async/toggle
|
||||
'async/transduce async/transduce
|
||||
'async/unblocking-buffer? async/unblocking-buffer?
|
||||
'async/unique async/unique
|
||||
'async/unmix async/unmix
|
||||
'async/unmix-all async/unmix-all
|
||||
'async/unsub async/unsub
|
||||
'async/unsub-all async/unsub-all
|
||||
'async/untap async/untap
|
||||
'async/untap-all async/untap-all})
|
||||
(def async-namespace
|
||||
{'<!! async/<!!
|
||||
'>!! async/>!!
|
||||
'admix async/admix
|
||||
'alts! async/alts!
|
||||
'alts!! async/alts!!
|
||||
'buffer async/buffer
|
||||
'chan async/chan
|
||||
'close! async/close!
|
||||
'do-alt async/do-alt
|
||||
'do-alts async/do-alts
|
||||
'dropping-buffer async/dropping-buffer
|
||||
'filter< async/filter<
|
||||
'filter> async/filter>
|
||||
'into async/into
|
||||
'map async/map
|
||||
'map< async/map<
|
||||
'map> async/map>
|
||||
'mapcat< async/mapcat<
|
||||
'mapcat> async/mapcat>
|
||||
'merge async/merge
|
||||
'mix async/mix
|
||||
'mult async/mult
|
||||
'offer! async/offer!
|
||||
'onto-chan async/onto-chan
|
||||
'partition async/partition
|
||||
'partition-by async/partition-by
|
||||
'pipe async/pipe
|
||||
'pipeline async/pipeline
|
||||
'pipeline-async async/pipeline-async
|
||||
'pipeline-blocking async/pipeline-blocking
|
||||
'poll! async/poll!
|
||||
'promise-chan async/promise-chan
|
||||
'pub async/pub
|
||||
'put! async/put!
|
||||
'reduce async/reduce
|
||||
'remove< async/remove<
|
||||
'remove> async/remove>
|
||||
'sliding-buffer async/sliding-buffer
|
||||
'solo-mode async/solo-mode
|
||||
'split async/split
|
||||
'sub async/sub
|
||||
'take async/take
|
||||
'take! async/take!
|
||||
'tap async/tap
|
||||
'thread (with-meta thread {:sci/macro true})
|
||||
'thread-call async/thread-call
|
||||
'timeout async/timeout
|
||||
'to-chan async/to-chan
|
||||
'toggle async/toggle
|
||||
'transduce async/transduce
|
||||
'unblocking-buffer? async/unblocking-buffer?
|
||||
'unique async/unique
|
||||
'unmix async/unmix
|
||||
'unmix-all async/unmix-all
|
||||
'unsub async/unsub
|
||||
'unsub-all async/unsub-all
|
||||
'untap async/untap
|
||||
'untap-all async/untap-all})
|
||||
|
||||
|
|
|
|||
|
|
@ -7,8 +7,7 @@
|
|||
`(~'future-call (fn [] ~@body)))
|
||||
|
||||
(def core-bindings
|
||||
{;; atoms
|
||||
'atom atom
|
||||
{'atom atom
|
||||
'swap! swap!
|
||||
'swap-vals! swap-vals!
|
||||
'reset! reset!
|
||||
|
|
@ -41,4 +40,5 @@
|
|||
'flush flush
|
||||
'ex-info ex-info
|
||||
'ex-data ex-data
|
||||
'read-line read-line})
|
||||
'read-line read-line
|
||||
'namespace namespace})
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
(ns babashka.impl.clojure.java.io
|
||||
(:require [clojure.java.io :as io]))
|
||||
|
||||
(def io-bindings
|
||||
{'io/as-relative-path io/as-relative-path
|
||||
'io/copy io/copy
|
||||
'io/delete-file io/delete-file
|
||||
'io/file io/file
|
||||
'io/input-stream io/input-stream
|
||||
'io/make-parents io/make-parents
|
||||
'io/output-stream io/output-stream
|
||||
'io/reader io/reader
|
||||
'io/writer io/writer})
|
||||
(def io-namespace
|
||||
{'as-relative-path io/as-relative-path
|
||||
'copy io/copy
|
||||
'delete-file io/delete-file
|
||||
'file io/file
|
||||
'input-stream io/input-stream
|
||||
'make-parents io/make-parents
|
||||
'output-stream io/output-stream
|
||||
'reader io/reader
|
||||
'writer io/writer})
|
||||
|
|
|
|||
|
|
@ -3,16 +3,16 @@
|
|||
(:require
|
||||
[babashka.impl.me.raynes.conch.low-level :as ll]))
|
||||
|
||||
(def conch-bindings
|
||||
(def conch-namespace
|
||||
{;; low level API
|
||||
'conch/proc ll/proc
|
||||
'conch/destroy ll/destroy
|
||||
'conch/exit-code ll/exit-code
|
||||
'conch/flush ll/flush
|
||||
'conch/done ll/done
|
||||
'conch/stream-to ll/stream-to
|
||||
'conch/feed-from ll/feed-from
|
||||
'conch/stream-to-string ll/stream-to-string
|
||||
'conch/stream-to-out ll/stream-to-out
|
||||
'conch/feed-from-string ll/feed-from-string
|
||||
'conch/read-line ll/read-line})
|
||||
'proc ll/proc
|
||||
'destroy ll/destroy
|
||||
'exit-code ll/exit-code
|
||||
'flush ll/flush
|
||||
'done ll/done
|
||||
'stream-to ll/stream-to
|
||||
'feed-from ll/feed-from
|
||||
'stream-to-string ll/stream-to-string
|
||||
'stream-to-out ll/stream-to-out
|
||||
'feed-from-string ll/feed-from-string
|
||||
'read-line ll/read-line})
|
||||
|
|
|
|||
9
src/babashka/impl/tools/cli.clj
Normal file
9
src/babashka/impl/tools/cli.clj
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
(ns babashka.impl.tools.cli
|
||||
{:no-doc true}
|
||||
(:require [clojure.tools.cli :as tools.cli]))
|
||||
|
||||
(def tools-cli-namespace
|
||||
{'format-lines tools.cli/format-lines
|
||||
'summarize tools.cli/summarize
|
||||
'get-default-options tools.cli/get-default-options
|
||||
'parse-opts tools.cli/parse-opts})
|
||||
|
|
@ -4,13 +4,14 @@
|
|||
[babashka.impl.File :refer [file-bindings]]
|
||||
[babashka.impl.System :refer [system-bindings]]
|
||||
[babashka.impl.Thread :refer [thread-bindings]]
|
||||
[babashka.impl.async :refer [async-bindings]]
|
||||
[babashka.impl.async :refer [async-namespace]]
|
||||
[babashka.impl.clojure.core :refer [core-bindings]]
|
||||
[babashka.impl.clojure.java.io :refer [io-bindings]]
|
||||
[babashka.impl.clojure.java.io :refer [io-namespace]]
|
||||
[babashka.impl.clojure.stacktrace :refer [print-stack-trace]]
|
||||
[babashka.impl.conch :refer [conch-bindings]]
|
||||
[babashka.impl.conch :refer [conch-namespace]]
|
||||
[babashka.impl.pipe-signal-handler :refer [handle-pipe! pipe-signal-received?]]
|
||||
[babashka.impl.socket-repl :as socket-repl]
|
||||
[babashka.impl.tools.cli :refer [tools-cli-namespace]]
|
||||
[babashka.net :as net]
|
||||
[clojure.edn :as edn]
|
||||
[clojure.java.io :as io]
|
||||
|
|
@ -140,19 +141,10 @@ Everything after that is bound to *command-line-args*."))
|
|||
(throw (Exception. (str "File does not exist: " file))))))
|
||||
|
||||
(def bindings
|
||||
(merge {'shell/sh shell/sh
|
||||
'namespace namespace
|
||||
;; clojure.java.io
|
||||
'edn/read-string edn/read-string
|
||||
'net/wait-for-it net/wait-for-it
|
||||
'sig/pipe-signal-received? pipe-signal-received?}
|
||||
core-bindings
|
||||
io-bindings
|
||||
(merge core-bindings
|
||||
system-bindings
|
||||
file-bindings
|
||||
thread-bindings
|
||||
conch-bindings
|
||||
async-bindings))
|
||||
thread-bindings))
|
||||
|
||||
(defn read-edn []
|
||||
(edn/read {;;:readers *data-readers*
|
||||
|
|
@ -194,7 +186,23 @@ Everything after that is bound to *command-line-args*."))
|
|||
:else
|
||||
(edn/read *in*))))))
|
||||
env (atom {})
|
||||
ctx {:bindings (assoc bindings '*command-line-args* command-line-args)
|
||||
ctx {:aliases '{tools.cli 'clojure.tools.cli
|
||||
edn clojure.edn
|
||||
net babashka.net
|
||||
sig babashka.signal
|
||||
shell clojure.java.shell
|
||||
io clojure.java.io
|
||||
conch me.raynes.conch.low-level
|
||||
async clojure.core.async}
|
||||
:namespaces {'clojure.tools.cli tools-cli-namespace
|
||||
'clojure.edn {'read-string edn/read-string}
|
||||
'clojure.java.shell {'sh shell/sh}
|
||||
'babashka.net {'wait-for-it net/wait-for-it}
|
||||
'babashka.signal {'pipe-signal-received? pipe-signal-received?}
|
||||
'clojure.java.io io-namespace
|
||||
'me.raynes.conch.low-level conch-namespace
|
||||
'clojure.core.async async-namespace}
|
||||
:bindings (assoc bindings '*command-line-args* command-line-args)
|
||||
:env env}
|
||||
ctx (update ctx :bindings assoc 'load-file #(load-file* ctx %))
|
||||
_preloads (some-> (System/getenv "BABASHKA_PRELOADS") (str/trim) (sci/eval-string ctx))
|
||||
|
|
|
|||
|
|
@ -185,3 +185,6 @@
|
|||
(-> (async/alts!! [(async-command \"sleep 2 && echo process 1\")
|
||||
(async-command \"sleep 1 && echo process 2\")])
|
||||
first :out str/trim println)"))))
|
||||
|
||||
(deftest tools-cli-test
|
||||
(is (= {:file "README.md"} (bb nil "test/babashka/scripts/tools.cli.bb"))))
|
||||
|
|
|
|||
2
test/babashka/scripts/tools.cli.bb
Normal file
2
test/babashka/scripts/tools.cli.bb
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
(require '[clojure.tools.cli :refer [parse-opts]])
|
||||
(:options (parse-opts ["-f" "README.md"] [["-f" "--file FILE" "file"]]))
|
||||
Loading…
Reference in a new issue