summaryrefslogtreecommitdiff
path: root/src/jvm/clojure
diff options
context:
space:
mode:
authorRich Hickey <richhickey@gmail.com>2008-08-07 11:47:36 +0000
committerRich Hickey <richhickey@gmail.com>2008-08-07 11:47:36 +0000
commit24118f2aca814de17946573930d174684a760ee8 (patch)
treead8b5609877c8d1323fa6d4f16f96aed80ae5316 /src/jvm/clojure
parenteebc10943d8daa1514e6a626dc29bebd1e1106a0 (diff)
added support for loading scripts from classpath, from cemerick
Diffstat (limited to 'src/jvm/clojure')
-rw-r--r--src/jvm/clojure/lang/Script.java46
1 files changed, 43 insertions, 3 deletions
diff --git a/src/jvm/clojure/lang/Script.java b/src/jvm/clojure/lang/Script.java
index 08f8bbe6..a14c9600 100644
--- a/src/jvm/clojure/lang/Script.java
+++ b/src/jvm/clojure/lang/Script.java
@@ -17,13 +17,53 @@ import java.io.IOException;
import java.util.List;
import java.util.Arrays;
+/**
+ * <code>Script</code> provides a way to run one or more Clojure files
+ * from a command line. Example usage:
+ * <p>
+ * <pre>java -cp clojure.jar script1.clj @/dir/script2.clj -- [arguments]</pre>
+ * </p>
+ * <p>
+ * The example above will:
+ * <ol>
+ * <li>bind *command-line-args* to a seq containing the (optional) arguments provided
+ * after the two dashes (--); this provides a way to provide command-line arguments
+ * to your scripts</li>
+ * <li>load the Clojure file <i>at the filesystem path</i> <code>script1.clj</code></li>
+ * <li>load the Clojure file with the name <code>dir/script2.clj</code> <i>from the
+ * current Java classpath</i>. Files to be loaded from the classpath must be prefixed
+ * with a '@' character, and must be an "absolute path" to the classpath resource.
+ * Note that the "path" will be treated as absolute within the classpath, whether it is
+ * prefixed with a slash or not.</li>
+ * </ol>
+ * </p>
+ * <p>
+ * Any number of Clojure files can be provided as path arguments; these
+ * files are loaded in order, as if via <code>load-file</code>. Filesystem and classpath
+ * paths may be provided in any order, and be intermixed as necessary.
+ * </p>
+ * <p>
+ * Once the final script path has been loaded, the java process exits.
+ * </p>
+ */
public class Script{
-public static void main(String[] args) throws Exception{
- try
+public static void main(String[] args) throws Exception{
+ try
{
for(String file : RT.processCommandLine(args))
- Compiler.loadFile(file);
+ {
+ if (file.startsWith("@"))
+ {
+ // trim leading slash if it's there -- loadResourceScript prepends its
+ // own slash to every name it's given
+ RT.loadResourceScript(file.substring(file.startsWith("@/") ? 2 : 1));
+ }
+ else
+ {
+ Compiler.loadFile(file);
+ }
+ }
}
finally
{