Skip to content

Commit

Permalink
dude
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude committed Jan 2, 2024
1 parent fb3853d commit 0d7e3c2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/babashka/cli.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -566,9 +566,17 @@

(defn- table->tree [table]
(reduce (fn [tree {:as cfg :keys [cmds]}]
(assoc-in tree (interleave (repeat :cmd) cmds) (dissoc cfg :cmds)))
(let [ks (interleave (repeat :cmd) cmds)]
(if (seq ks)
(assoc-in tree ks (dissoc cfg :cmds))
;; catch-all
(merge tree (dissoc cfg :cmds)))))
{} table))

(comment
(table->tree [{:cmds [] :fn identity}])
)

(defn- deep-merge [a b]
(reduce (fn [acc k] (update acc k (fn [v]
(if (map? v)
Expand All @@ -588,7 +596,7 @@
([tree args]
(dispatch-tree' tree args nil))
([tree args opts]
(def t tree)
#_(def t tree)
(loop [cmds [] all-opts {} args args cmd-info tree]
(let [;; cmd-info (:cmd cmd-info)
kwm cmd-info #_(select-keys cmd-info (filter keyword? (keys cmd-info)))
Expand All @@ -614,9 +622,9 @@
(if arg
{:error :no-match
:wrong-input arg
:available-commands (filter string? (keys cmd-info))}
:available-commands (keys (:cmd cmd-info))}
{:error :input-exhausted
:available-commands (filter string? (keys cmd-info))})))))))
:available-commands (keys (:cmd cmd-info))})))))))

(comment
(dispatch [{:cmds ["foo"] :fn identity}
Expand Down
1 change: 1 addition & 0 deletions test/babashka/cli_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@
:fn identity}])))))

;; TODO, test
;; TODO: add [] test
#_(dispatch [{:cmds ["foo" "bar"]
:spec {:foo {:coerce :keyword}}
:fn identity}] ["foo" "bar" "--foo" "dude"])
Expand Down

0 comments on commit 0d7e3c2

Please sign in to comment.