planck

Planck ClojureScript REPL
bherrmann 2016-11-21T03:22:14.000490Z

Humm... how would i use clojure/tools.cli with planck? I want to use parse-opts to do command line option processing

bherrmann 2016-11-21T03:28:51.000491Z

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}}

mfikes 2016-11-21T03:32:50.000492Z

@bherrmann Do you have that JAR on Planck’s classpath? I have never tried it before. Let me see...

bherrmann 2016-11-21T03:33:15.000493Z

no I was hoping it was a part of core

bherrmann 2016-11-21T03:34:51.000494Z

https://github.com/clojure/tools.cli

bherrmann 2016-11-21T03:41:27.000497Z

$ planck -c tools.cli-0.3.5.jar

bherrmann 2016-11-21T03:41:47.000498Z

cljs.user=> (ns cljs.user (:require [clojure.tools.cli :refer [parse-opts]])) nil

bherrmann 2016-11-21T03:41:55.000499Z

seems like it is working.

bherrmann 2016-11-21T03:42:18.000500Z

manually downloading a jar file - feels like a stoneage activity.

bherrmann 2016-11-21T03:42:28.000501Z

I'm used to maven / npm

mfikes 2016-11-21T03:43:22.000502Z

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}}

mfikes 2016-11-21T03:43:49.000503Z

$ 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)))

mfikes 2016-11-21T03:44:44.000504Z

You can get Leiningen or Boot to download the dependency for you. See http://planck-repl.org/dependencies.html

mfikes 2016-11-21T03:45:10.000505Z

I used Leiningen with

(defproject foo "0.1.0-SNAPSHOT"
  :dependencies [[org.clojure/tools.cli “0.3.5”]])

bherrmann 2016-11-21T03:45:10.000506Z

great thanks

mfikes 2016-11-21T04:09:36.000507Z

Added the above as an example to the Planck docs: https://github.com/mfikes/planck/blob/master/site/src/scripts.md#argument-processing