Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude committed Nov 3, 2023
1 parent ee4f5a7 commit 5dd1a24
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
12 changes: 9 additions & 3 deletions src/babashka/cli.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@
(let [arg-count (count args)
cnt (min arg-count
(bounded-count arg-count args->opts))]
[(concat (interleave args->opts args)
[(concat (interleave #?(:squint (map vector args->opts)
:default args->opts) args)
(drop cnt args))
(drop cnt args->opts)])
[args args->opts])
Expand Down Expand Up @@ -348,11 +349,16 @@
mode (when no-keyword-opts :hyphens)
args (seq args)
a->o a->o]
#_(prn :acc acc :current-opt current-opt :added added :mode (str mode) :args args :a-o a->o)
(if-not args
[acc current-opt added]
(let [raw-arg (first args)
opt? #?(:squint false
:default (keyword? raw-arg))]
opt? #?(:squint (vector? raw-arg)
:default (keyword? raw-arg))
raw-arg #?(:squint (if opt?
(first raw-arg)
raw-arg)
:default raw-arg)]
(if opt?
(recur (process-previous acc current-opt added nil)
raw-arg added mode (next args)
Expand Down
2 changes: 1 addition & 1 deletion test/babashka/cli_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
:option :b
:value "dude"
:spec nil}
(ex-data e)))))
(ex-data e)))))
(is (submap? {:a [1 1]}
(cli/parse-opts ["-a" "1" "-a" "1"] {:collect {:a []} :coerce {:a :long}})))
(is (submap? {:foo :bar
Expand Down
5 changes: 5 additions & 0 deletions test/babashka/one_off.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(ns babashka.one-off
(:require [babashka.cli :as cli]))

(prn (cli/parse-opts ["2021a4" ":no-git-tag-version" ":deps-file" "foo.edn"] {:args->opts [:version] :spec {:no-git-tag-version {:coerce :boolean}}}))
(prn (cli/parse-opts ["foo"] {:args->opts [:bar]}))

0 comments on commit 5dd1a24

Please sign in to comment.