Created
September 22, 2010 23:52
-
-
Save rberger/592806 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env cake | |
;; From http://stackoverflow.com/questions/1341154/building-a-clojure-app-with-a-command-line-interface | |
(ns testcake.core | |
(:use clojure.contrib.command-line)) | |
(defn -main [& args] | |
(with-command-line args | |
"Command line demo" | |
[[foo "This is the description for foo" 1] | |
[bar "This is the description for bar" 2] | |
[boolean? b? "This is a boolean flag."] | |
remaining] | |
(println "foo: " foo) | |
(println "bar: " bar) | |
(println "boolean?: " boolean?) | |
(println "remaining: " remaining))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defproject testcake "1.0.0-SNAPSHOT" | |
:description "Testing Cake and Clojure command lines" | |
:dependencies [[org.clojure/clojure "1.2.0"] | |
[org.clojure/clojure-contrib "1.2.0"]] | |
:main testcake.core | |
:dev-dependencies [[swank-clojure "1.2.1"]]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
If I execute it with the vanilla java command line it works correctly: | |
$ java -jar testcake-1.0.0-SNAPSHOT-standalone.jar --foo "changed value" | |
foo: changed value | |
bar: 2 | |
boolean?: nil | |
remaining: [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
When I run with the result of the cake bin, its breaking up the string being passed in to --foo instead of treating it as a single string | |
$ cake bin | |
[compile] Restarting project jvm. | |
[jar] Building jar: /Users/rberger/work/runa/testcake/testcake-1.0.0-SNAPSHOT.jar | |
[uberjar] Building jar: /Users/rberger/work/runa/testcake/testcake-1.0.0-SNAPSHOT-standalone.jar | |
[bin] Creating standalone executable: /Users/rberger/work/runa/testcake/testcake | |
$ ./testcake --foo "changed value" | |
foo: changed | |
bar: 2 | |
boolean?: nil | |
remaining: [value] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment