I am trying to write a library to do some domain specific things. I would like to add some scripts to this library that can be run directly from the command line.
Directory Layout:
+- project.clj +- src/ | +- my-lib.clj | +- my-lib/ | +- my-sub-1.clj +- scripts/ +- run-command.sh
The src / my-lib.clj file loads the my-lib / my-sub-1.clj file:
(ns my-lib (:use [my-lib.my-sub-1]) )
The src / my-lib / my-sub-1.clj file contains the functions that I want to make available. One of these functions is called "convert" and takes two arguments: the name of the input file and the name of the output file; it converts the file. To use it:
(convert "input-file.txt" "output-file.txt")
The functions (do something interesting) and (convert) to src / my-lib / my-sub-1.clj look like this:
(defn do-something-interesting [input-file output-file] (magic-happens-here input-file output-file)) (defn convert [args] (let [infile (first args) outfile (second args)] (do-something-interesting infile outfile)))
My goal at the moment is to create a script "run-command.sh" in the "scripts" directory that takes two arguments: the name of the input file and the name of the output file. It should be possible to run the script with:
./run-command.sh input-file.txt output-file.txt
I have a run-command.sh job if I hard code the file names in this script using the (do-something-interesting) function instead of (convert). I have not yet been able to read the argument list ...
The run-command.sh script command works:
#!/bin/sh java -cp "../lib/*":"../src":$CLASSPATH clojure.main -e " (use '[my-lib my-sub-1]) (do-something-interesting "path-to-input-file" "path-to-output-file") "
... but what does not work:
#!/bin/sh java -cp "../lib/*":"../src":$CLASSPATH clojure.main -e " (use '[my-lib my-sub-1]) (convert *command-line-args*) "
The error I am getting is:
Exception in thread "main" java.lang.IllegalArgumentException: No implementation of method: :reader of protocol:
I tried using the "ing" clojure.contrib.io in the script file run-command.sh file itself and in the top library file my-lib.clj, but so far no luck ..
If anyone can help me, it will be great.
January