Skip to content

Commit

Permalink
v0.8.55
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude committed Jan 4, 2024
1 parent a55c539 commit c970a4d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ For breaking changes, check [here](#breaking-changes).

[Babashka CLI](https://github.com/babashka/cli): turn Clojure functions into CLIs!

## v0.8.55 (2024-01-04)

- Fix `--no-option` (`--no` prefix) in combination with subcommands

## v0.8.54 (2024-01-04)

- Prioritize `:exec-args` over spec `:default`s
Expand Down
24 changes: 12 additions & 12 deletions src/babashka/cli.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,7 @@
[opts last-opt added]
(if (and (::dispatch-tree opts)
(seq cmds))
(do
;; (prn :result-to-dispatch cmds args :> (into (vec cmds) args))
[(vary-meta {} assoc-in [:org.babashka/cli :args] (into (vec cmds) args)) nil nil])
[(vary-meta {} assoc-in [:org.babashka/cli :args] (into (vec cmds) args)) nil nil]
(loop [acc {}
current-opt nil
added nil
Expand Down Expand Up @@ -385,9 +383,12 @@
k nil mode (cons arg-val (rest args)) a->o)
(let [next-args (next args)
next-arg (first next-args)
m (parse-key next-arg mode current-opt coerce-opt added)]
m (parse-key next-arg mode current-opt coerce-opt added)
negative? (when-not (contains? known-keys k)
(str/starts-with? (str k) ":no-"))]
(if (or (:hyphen-opt m)
(empty? next-args))
(empty? next-args)
negative?)
;; implicit true
(if composite-opt
(let [chars (name k)
Expand All @@ -398,9 +399,7 @@
(recur acc
nil nil mode next-args
a->o))
(let [negative? (when-not (contains? known-keys k)
(str/starts-with? (str k) ":no-"))
k (if negative?
(let [k (if negative?
(keyword (str/replace (str k) ":no-" ""))
k)
next-args (cons (not negative?) #_"true" next-args)]
Expand Down Expand Up @@ -621,7 +620,6 @@
::dispatch-tree-ignored-args (set (keys (:cmd cmd-info)))))
{:args args
:opts {}})
;; _ (prn :dispatch-args-post args)
[arg & rest] args
all-opts (-> (merge all-opts opts)
(update ::opts-by-cmds (fnil conj []) {:cmds cmds
Expand All @@ -639,9 +637,11 @@
(if arg
{:error :no-match
:wrong-input arg
:available-commands (keys (:cmd cmd-info))}
:available-commands (keys (:cmd cmd-info))
:opts (dissoc all-opts ::opts-by-cmds)}
{:error :input-exhausted
:available-commands (keys (:cmd cmd-info))})))))))
:available-commands (keys (:cmd cmd-info))
:opts (dissoc all-opts ::opts-by-cmds)})))))))

(defn- dispatch-tree
([tree args]
Expand All @@ -660,7 +660,7 @@
error-fn*))]
(case error
(:no-match :input-exhausted)
(error-fn {:cause error})
(error-fn {:cause error :opts (:opts res)})
nil ((:fn cmd-info) (dissoc res :cmd-info))))))

(defn dispatch
Expand Down
4 changes: 3 additions & 1 deletion test/babashka/cli_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@
(cli/parse-opts ["--foo" "-abc"]))))
(testing "--no- prefix"
(is (= {:option false, :no-this-exists true}
(cli/parse-opts ["--no-option" "--no-this-exists"] {:coerce {:no-this-exists :bool}})))))
(cli/parse-opts ["--no-option" "--no-this-exists"] {:coerce {:no-this-exists :bool}})))
(is (= {:args ["dude"], :opts {:option false}}
(cli/parse-args ["--no-option" "dude"] {:coerce {:option :bool}})))))

(deftest parse-opts-keywords-test
(is (= {:version "2021a4", :no-git-tag-version true, :deps-file "foo.edn"}
Expand Down
2 changes: 1 addition & 1 deletion version.edn
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{:major 0, :minor 8, :release 54}
{:major 0, :minor 8, :release 55}

0 comments on commit c970a4d

Please sign in to comment.