Back

main (clj)

(source)

function

(main & args)
Usage: java -cp clojure.jar clojure.main [init-opt*] [main-opt] [arg*] With no options or args, runs an interactive Read-Eval-Print Loop init options: -i, --init path Load a file or resource -e, --eval string Evaluate expressions in string; print non-nil values --report target Report uncaught exception to "file" (default), "stderr", or "none", overrides System property clojure.main.report main options: -m, --main ns-name Call the -main function from a namespace with args -r, --repl Run a repl path Run a script from a file or resource - Run a script from standard input -h, -?, --help Print this help message and exit operation: - Establishes thread-local bindings for commonly set!-able vars - Enters the user namespace - Binds *command-line-args* to a seq of strings containing command line args that appear after any main option - Runs all init options in order - Calls a -main function or runs a repl or script if requested The init options may be repeated and mixed freely, but must appear before any main option. The appearance of any eval option before running a repl suppresses the usual repl greeting message: "Clojure ~(clojure-version)". Paths may be absolute or relative in the filesystem or relative to classpath. Classpath-relative paths have prefix of @ or @/

Examples

clojure

(ns clojure.test-clojure.main
  (:use clojure.test
        [clojure.test-helper :only [platform-newlines]])
  (:require [clojure.main :as main]))

(deftest eval-opt
  (testing "evals and prints forms"
    (is (= (platform-newlines "2\n4\n") (with-out-str (#'clojure.main/eval-opt "(+ 1 1) (+ 2 2)")))))

  (testing "skips printing nils"
    (is (= (platform-newlines ":a\n:c\n") (with-out-str (#'clojure.main/eval-opt ":a nil :c")))))

  (testing "does not block access to *in* (#299)"
    (with-in-str "(+ 1 1)"
      (is (= (platform-newlines "(+ 1 1)\n") (with-out-str (#'clojure.main/eval-opt "(read)")))))))

(defn run-repl-and-return-err
  "Run repl, swallowing stdout and returing stderr."
  [in-str]
  (with-err-str
    (with-out-str
      (with-in-str in-str
        (main/repl)))))

(deftest null-stack-error-reporting
  (let [e (doto (Error. "xyz")
            (.setStackTrace (into-array java.lang.StackTraceElement nil)))
        tr-data (-> e Throwable->map main/ex-triage)]
    (is (= tr-data #:clojure.error{:phase :execution, :class 'java.lang.Error, :cause "xyz"}))
    (is (= (main/ex-str tr-data) (platform-newlines "Execution error (Error) at (REPL:1).\nxyz\n")))))

(deftest renumbering-read
  (are [s line-in line-out]
    (= line-out (-> (main/renumbering-read nil (s->lpr s) line-in) meta :line))
    "(let [x 1] x)" 100 100
    "^{:line 20 :clojure.core/eval-file \"a/b.clj\"} (let [x 1] x)" 100 20
    "^{:line 20} (let [x 1] x)" 100 20))

(deftest java-loc->source
  (are [c m out]
    (= out (#'main/java-loc->source c m))
    'user$eval1                'invokeStatic 'user/eval1
    'div$go                    'invokeStatic 'div/go
    'user$eval186$fn__187      'invoke       'user/eval186$fn
    'user$ok_fn$broken_fn__164 'invoke       'user/ok-fn$broken-fn
    'clojure.lang.Numbers      'divide       'clojure.lang.Numbers/divide))
djblue/portal
(require '[babashka.deps :as deps])
(require '[clojure.main :as main])

(main/repl)
NoahTheDuke/splint
(ns user
  (:require
    [clj-java-decompiler.core :as decompiler]
    [clojure.main :as main]
    [clojure.tools.namespace.repl :as tns]
    [criterium.core :as criterium]
    [noahtheduke.splint.dev]
    [potemkin :refer [import-vars]]
    [taoensso.tufte :as tufte]))

(apply require main/repl-requires)
funcool/potok
(require '[clojure.java.shell :as shell]
         '[clojure.main])
(require '[rebel-readline.core]
         '[rebel-readline.clojure.main]
         '[rebel-readline.clojure.line-reader]
         '[rebel-readline.clojure.service.local]
         '[rebel-readline.cljs.service.local]
         '[rebel-readline.cljs.repl])
(require '[cljs.build.api :as api]
         '[cljs.repl :as repl]
         '[cljs.repl.node :as node])

(defmethod task "repl:jvm"
  [args]
  (rebel-readline.core/with-line-reader
    (rebel-readline.clojure.line-reader/create
     (rebel-readline.clojure.service.local/create))
    (clojure.main/repl
     :prompt (fn []) ;; prompt is handled by line-reader
     :read (rebel-readline.clojure.main/create-repl-read))))

(def build-options
  {:main 'potok.tests
   :output-to "out/tests.js"
   :output-dir "out/tests"
   :source-map "out/tests.js.map"
   :target :nodejs
   :optimizations :advanced
   :pretty-print true
   :pseudo-names true
   :verbose true})