Humm... how would i use clojure/tools.cli with planck? I want to use parse-opts to do command line option processing
cljs.user=> (ns cljs.user (:require [clojure.tools.cli :refer [parse-opts]])) #error {:message No such namespace: cljs.tools.cli, could not locate cljs/tools/cli.cljs, cljs/tools/cli.cljc, or Closure namespace "cljs.tools.cli", :data {:tag :cljs/analysis-error}}
@bherrmann Do you have that JAR on Planck’s classpath? I have never tried it before. Let me see...
no I was hoping it was a part of core
$ wget http://search.maven.org/remotecontent?filepath=org/clojure/tools.cli/0.3.5/tools.cli-0.3.5.jar
$ planck -c tools.cli-0.3.5.jar
cljs.user=> (ns cljs.user (:require [clojure.tools.cli :refer [parse-opts]])) nil
seems like it is working.
manually downloading a jar file - feels like a stoneage activity.
I'm used to maven / npm
It worked for me 🙂
planck -c /Users/mfikes/.m2/repository/org/clojure/tools.cli/0.3.5/tools.cli-0.3.5.jar -m my.program -vvvp8080 foo --help --invalid-opt
{:errors ["Unknown option: \"--invalid-opt\""], :arguments ["foo"], :summary " -p, --port PORT 80 Port number\n -v Verbosity level\n -h, --help", :options {:port 8080, :verbosity 3, :help true}}
$ cat my/program.cljs
(ns my.program
(:require [clojure.tools.cli :refer [parse-opts]]))
(def cli-options
;; An option with a required argument
[["-p" "--port PORT" "Port number"
:default 80
:parse-fn #(js/parseInt %)
:validate [#(< 0 % 0x10000) "Must be a number between 0 and 65536"]]
;; A non-idempotent option
["-v" nil "Verbosity level"
:id :verbosity
:default 0
:assoc-fn (fn [m k _] (update-in m [k] inc))]
;; A boolean option defaulting to nil
["-h" "--help"]])
(defn -main [& args]
(prn (parse-opts args cli-options)))
You can get Leiningen or Boot to download the dependency for you. See http://planck-repl.org/dependencies.html
I used Leiningen with
(defproject foo "0.1.0-SNAPSHOT"
:dependencies [[org.clojure/tools.cli “0.3.5”]])
great thanks
Added the above as an example to the Planck docs: https://github.com/mfikes/planck/blob/master/site/src/scripts.md#argument-processing