This commit is contained in:
Michiel Borkent 2022-07-31 13:57:00 +02:00
parent de43917140
commit b0de4a79a4
2 changed files with 13 additions and 5 deletions

View file

@ -8,21 +8,26 @@
(def cli-namespace
(sci/copy-ns babashka.cli cns))
(defn exec-fn-snippet [sym]
(format "
(defn exec-fn-snippet
([sym] (exec-fn-snippet sym nil))
([sym extra-opts]
(format "
(do
(require '[babashka.cli])
(let [the-var (requiring-resolve `%1$s)
(let [extra-opts '%2$s
the-var (requiring-resolve `%1$s)
the-var-meta (meta the-var)
ns (:ns (meta the-var))
ns-meta (meta ns)
ct (babashka.tasks/current-task)
cli-opts (babashka.cli/merge-opts (:org.babashka/cli ns-meta)
(:org.babashka/cli the-var-meta)
(:org.babashka/cli ct))
(:org.babashka/cli ct)
extra-opts)
opts (babashka.cli/parse-opts *command-line-args* cli-opts)
task-exec-args (:exec-args ct)
cli-exec-args (:exec-args cli-opts)
opts (babashka.cli/merge-opts cli-exec-args task-exec-args opts)]
(the-var opts)))"
sym))
sym
(pr-str extra-opts))))

View file

@ -460,6 +460,9 @@
(defn exec
([sym]
(let [snippet (cli/exec-fn-snippet sym)]
(sci/eval-string* @ctx snippet)))
([sym extra-opts]
(let [snippet (cli/exec-fn-snippet sym extra-opts)]
(sci/eval-string* @ctx snippet))))
(def tasks-namespace