Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Read forms from stdin when no args are provided.

Fixes #13.
  • Loading branch information...
commit 42fbc2742db53099d5276f35149dd8fffbac6dee 1 parent 296114d
@technomancy authored
Showing with 24 additions and 13 deletions.
  1. +6 −4 README.md
  2. +4 −0 client.ml
  3. +14 −9 grench.ml
View
10 README.md
@@ -30,10 +30,12 @@ To build, run the following commands:
Grenchman has four main commands:
-* `grench main my.main.ns arg1 arg2` - to run an existing `-main` defn
-* `grench eval "(+ 12 49)"` - to run code provided as argument
-* `grench repl` or `grench repl :connect $PORT` - to connect a repl
-* `grench lein $TASK` - to run Leiningen tasks
+* `grench eval "(+ 12 49)"` - evals given form
+* `grench main my.main.ns/entry-point arg1 arg2` - runs existing defn
+* `grench repl` or `grench repl :connect $PORT` - connects a repl
+* `grench lein test` - runs a Leiningen task
+
+Running with no arguments will read code from stdin to accomodate shebangs.
Each of these commands connects to a running nREPL server in order to
avoid JVM startup time. The simplest way to start a project JVM is to
View
4 client.ml
@@ -130,3 +130,7 @@ let main port args =
| ns :: args -> let form = main_form ns (splice_args args) in
let messages = [eval_message form "user"] in
eval port messages handle_done
+
+let stdin_eval port =
+ let input = In_channel.input_lines stdin |> String.concat ~sep:"\n" in
+ main port ["clojure.main/main"; "-e"; input]
View
23 grench.ml
@@ -7,10 +7,13 @@ let usage = "Grenchman runs Clojure code quickly.
Commands:
- main NAMESPACE[/FUNCTION] [ARGS...] Run an existing project function.
- eval FORM Eval form inside project.
- repl [:connect PORT] Connect a repl.
- lein [TASK ARGS...] Run a Leiningen task.\n\n"
+ eval FORM Evals given form.
+ main NAMESPACE[/FUNCTION] [ARGS...] Runs existing defn.
+ repl [:connect PORT] Connects a repl.
+ lein [TASK ARGS...] Runs a Leiningen task.
+
+Running with no arguments will read code from stdin.
+"
let port_err = "Couldn't read port from .nrepl-port or $GRENCH_PORT.\n"
@@ -27,18 +30,20 @@ let repl_port port_file =
let () =
if ! Sys.interactive then () else
match Sys.argv |> Array.to_list |> List.tl with
- | None | Some ["--grench-help"] -> printf "%s\n%!" usage
+ | Some ["--grench-help"] -> printf "%s\n%!" usage
| Some ["--version"] | Some ["-v"] -> printf "Grenchman 0.1.0\n%!"
- | Some ["--leiningen-version"] | Some ["--lein-version"] ->
- Lein.main ["version"]
- | Some ("main" :: args) -> Client.main (repl_port ".nrepl-port") args
| Some ("eval" :: args) ->
Client.main (repl_port ".nrepl-port")
("clojure.main/main" :: "-e" :: args)
+ | Some ("main" :: args) -> Client.main (repl_port ".nrepl-port") args
+
| Some ["repl"] -> Repl.main (repl_port ".nrepl-port")
| Some ["repl"; ":connect"; port] -> Repl.main (int_of_string port)
+
| Some ("lein" :: args) -> Lein.main args
- | Some _ -> eprintf "Unknown command.\n\n%s" usage; exit 1
+ | None | Some [] -> Client.stdin_eval (repl_port ".nrepl-port")
+
+ | Some _ -> eprintf "Unknown command.\n\n%s" usage; exit 1
Please sign in to comment.
Something went wrong with that request. Please try again.