Allow 'repl :connect' to read args from file
This basically works like in curl, you specify @filename and then the contents of the file are literally used as if written on the CLI. @TODO this will not work: lein repl :connect @./some/file because there is no realpath resolution but this works: lein repl :connect @/full/path and this as well: lein repl :connect @some/file
This commit is contained in:
parent
2803647bc4
commit
2a2adb2aad
4 changed files with 30 additions and 8 deletions
|
@ -52,14 +52,27 @@
|
|||
s
|
||||
(main/abort "Port is required. See `lein help repl`")))
|
||||
|
||||
(defn string-from-file [arg]
|
||||
(if-let [filename-tmp (and (seq arg) (= "@" (subs arg 0 1)) (seq (subs arg 1)))]
|
||||
(let [filename (apply str filename-tmp)
|
||||
errmsg (str "The file '" filename "' can't be read.")]
|
||||
(if-let [content (try (slurp filename)
|
||||
(catch Exception e
|
||||
(main/abort errmsg)))]
|
||||
(s/trim content)
|
||||
(main/abort errmsg)))
|
||||
false))
|
||||
|
||||
(defn connect-string [project opts]
|
||||
(as-> (str (first opts)) x
|
||||
(s/split x #":")
|
||||
(let [opt (str (first opts))]
|
||||
(if-let [sx (string-from-file opt)]
|
||||
(connect-string project [sx])
|
||||
(as-> (s/split opt #":") x
|
||||
(remove s/blank? x)
|
||||
(-> (drop-last (count x) [(repl-host project) (client-repl-port project)])
|
||||
(concat x))
|
||||
(s/join ":" x)
|
||||
(ensure-port x)))
|
||||
(ensure-port x)))))
|
||||
|
||||
(defn options-for-reply [project & {:keys [attach port]}]
|
||||
(as-> (:repl-options project) opts
|
||||
|
|
|
@ -86,7 +86,14 @@
|
|||
["http://localhost/ham"] {:root "/tmp"}
|
||||
["foo1234"] {:root "/tmp"}
|
||||
[] {:root "/tmp"}
|
||||
[] lthelper/with-resources-project))
|
||||
[] lthelper/with-resources-project)
|
||||
(are [in proj]
|
||||
(is (re-find
|
||||
#"The file '.+' can't be read."
|
||||
(lthelper/abort-msg connect-string proj in)))
|
||||
["@/tmp/please-do-not-create-this-file-it-will-break-my-test"] {}))
|
||||
(is (= "myhost:23" (connect-string lthelper/sample-project ["@test/sample-connect-string"])))
|
||||
(is (= "http://localhost:23/repl" (connect-string lthelper/sample-project ["@test/sample-connect-string-http"])))
|
||||
|
||||
(is (= "127.0.0.1:4242" (connect-string lthelper/sample-project [])))
|
||||
(is (= "127.0.0.1:4343" (connect-string lthelper/sample-project ["4343"])))
|
||||
|
|
1
test/sample-connect-string
Normal file
1
test/sample-connect-string
Normal file
|
@ -0,0 +1 @@
|
|||
myhost:23
|
1
test/sample-connect-string-http
Normal file
1
test/sample-connect-string-http
Normal file
|
@ -0,0 +1 @@
|
|||
http://localhost:23/repl
|
Loading…
Reference in a new issue