This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-11-21
Channels
- # beginners (165)
- # boot (9)
- # cider (9)
- # cljs-dev (5)
- # cljsjs (5)
- # clojars (4)
- # clojure (207)
- # clojure-brasil (1)
- # clojure-greece (3)
- # clojure-poland (2)
- # clojure-russia (6)
- # clojure-spec (85)
- # clojure-taiwan (1)
- # clojure-uk (53)
- # clojurescript (96)
- # community-development (2)
- # cursive (4)
- # datomic (14)
- # emacs (41)
- # events (2)
- # hoplon (184)
- # leiningen (1)
- # nginx (1)
- # off-topic (16)
- # om (7)
- # onyx (63)
- # pedestal (27)
- # planck (17)
- # protorepl (3)
- # rdf (9)
- # re-frame (62)
- # reagent (7)
- # ring-swagger (5)
- # schema (2)
- # spacemacs (5)
- # test-check (25)
- # untangled (93)
- # yada (3)
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...
$ wget http://search.maven.org/remotecontent?filepath=org/clojure/tools.cli/0.3.5/tools.cli-0.3.5.jar
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”]])
Added the above as an example to the Planck docs: https://github.com/mfikes/planck/blob/master/site/src/scripts.md#argument-processing