Uploaded image for project: 'tools.cli'
  1. TCLI-94

ClojureScript Bug: Undeclared vars clojure.tools.cli/Exception and clojure.tools.cli/*err*

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Completed
    • Labels:
      None
    • Environment:

      OS X 10.14

      Description

      Problem

      When using clojure.tools.cli in ClojureScript two warnings are encountered suggestion incompatibility with ClojureScript:

      Unable to find source-code formatter for language: text. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      Resource: clojure/tools/cli.cljc:126:17
      Use of undeclared Var clojure.tools.cli/Exception
      
      Resource: clojure/tools/cli.cljc:228:25
      Use of undeclared Var clojure.tools.cli/*err*
      

      Reproduction

      1. Let's use shadow-cljs for the sake of speed. First, create a shadow-cljs.edn:

      shadow-cljs.edn
          {:source-paths ["src"]
           :dependencies [[org.clojure/tools.cli "0.4.1"]]
           :builds {:app {:output-to  "target/main.js"
                          :output-dir "target/js/compiled/prod"
                          :target     :node-script
                          :main       my-test-project.app/main!}}}
         

      2. Create a test cljs file:

      src/my_test_project/core.cljs
         (ns my-test-project.core
          (:require
           [clojure.tools.cli :refer [parse-opts]]))
           
         (def cli-options
           [["-p" "--port PORT" "Port number"
             :default 80
             :parse-fn #(js/Number %)
             :validate [#(< 0 % 0x10000) "Must be a number between 0 and 65536"]]
             ;; A non-idempotent option (:default is applied first)
            ["-v" nil "Verbosity level"
             :id :verbosity
             :default 0
             :update-fn inc] ; Prior to 0.4.1, you would have to use:
            ["-h" "--help"]]) 
         
         (defn -main
           [& args]
           (println (parse-opts args cli-options)))
           
      3. Start building it
         {code:shell}
         shadow-cljs watch app
         

      Expected

      I expect the build to finish without warnings with the expectation that tools.cli fully supports ClojureScript.

      Actual

      Several warnings are output because Exception and err vars do not exist in ClojureScript.

      Unable to find source-code formatter for language: text. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      ------ WARNING #1 - :undeclared-var --------------------------------------------
       Resource: clojure/tools/cli.cljc:126:17
      --------------------------------------------------------------------------------
       123 |          (recur options (into extra-args (vec (rest args))) nil)
       124 |
       125 |          (and (opt? opt) (nil? spec))
       126 |          (throw (Exception. (str "'" opt "' is not a valid argument")))
      -----------------------^--------------------------------------------------------
       Use of undeclared Var clojure.tools.cli/Exception
      --------------------------------------------------------------------------------
       127 |
       128 |          (and (opt? opt) (spec :flag))
       129 |          (recur ((spec :assoc-fn) options (spec :name) (flag-for opt))
       130 |                 extra-args
      --------------------------------------------------------------------------------
      
      ------ WARNING #2 - :undeclared-var --------------------------------------------
       Resource: clojure/tools/cli.cljc:228:25
      --------------------------------------------------------------------------------
       225 |   (when *assert*
       226 |     (let [unknown-keys (keys (apply dissoc map spec-keys))]
       227 |       (when (seq unknown-keys)
       228 |         (binding [*out* *err*]
      -------------------------------^------------------------------------------------
       Use of undeclared Var clojure.tools.cli/*err*
      --------------------------------------------------------------------------------
       229 |           (println (str "Warning: The following options to parse-opts are unrecognized: "
       230 |                         (s/join ", " unknown-keys)))))))
       231 |
       232 |   (select-keys map spec-keys))
      --------------------------------------------------------------------------------
      

        Attachments

          Activity

            People

            • Assignee:
              seancorfield Sean Corfield
              Reporter:
              alex+import import
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: