Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rberger/592806 to your computer and use it in GitHub Desktop.
Save rberger/592806 to your computer and use it in GitHub Desktop.
#!/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)))
(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"]])
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: []
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