boot-clj / boot

Build tooling for Clojure.
https://boot-clj.github.io/
Eclipse Public License 1.0
1.75k stars 180 forks source link

Optarg restrictions #615

Open martinklepsch opened 7 years ago

martinklepsch commented 7 years ago

Via Slack:

Hey. I've just wasted another hour and a half debugging WTH boot could not parse my string argument. Long story short, turned out that my arg definition:

[i input S3PATH str "blablabla"]

creates a parse function that turns the provided string into a vector, and then the verifier fails. Turns out the 3 in S3PATH was to blame. Nowhere in the documentation I could not find any mention that digits in the optarg name change > the parser behavior.

martinklepsch commented 7 years ago

As pointed out in Slack the culprit seems to be the (remove A-Z? ...) line in boot.cli.

Not sure what the loop in that function does I just did some basic testing with a modified impl of parse-fn, which seemed to be just fine. Maybe @micha remembers what the loop was all about? :)

;; build.boot
(alter-var-root
 #'boot.cli/parse-fn
 (fn [old-fn]
   (fn parse-fn [optarg]
     (fn [arg]
       ;; (prn :optarg optarg)
       ;; (prn :arg arg)
       (let [valid (or (nil? optarg)
                       (->> optarg str (re-find #"^[\d\w_]+$")))]
         ;; (prn :valid valid)
         (if valid
           arg
           (throw (ex-info "Invalid arg/optarg" {:arg arg :optarg optarg}))))))))

(deftask repro
  ;; try numbers or underscores here and things will fail unless you have the 
  ;; alter-var-root block above
  [a aaa MYTEST edn "edn"
   b bbb bool "boolean"
   c ccc ASTR str "string"
   d ddd STRS [str] "multiple strings"
   ]
  (with-pass-thru _
    (println "\nvalue of aaa:" (type aaa) (pr-str aaa))
    (println "\nvalue of bbb:" (type bbb) (pr-str bbb))
    (println "\nvalue of ccc:" (type ccc) (pr-str ccc))
    (println "\nvalue of ddd:" (type ddd) (pr-str ddd))))
$ boot repro --aaa abc --bbb --ccc 123 --ddd 123 --ddd dfg

EDIT: @micha said he doesn't remember what the loop was for so could be it's "dead".