This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-11-10
Channels
- # admin-announcements (1)
- # aleph (1)
- # asami (9)
- # babashka (30)
- # beginners (83)
- # calva (8)
- # cherry (4)
- # cider (4)
- # clj-kondo (15)
- # cljs-dev (11)
- # cljsrn (8)
- # clojure (85)
- # clojure-europe (87)
- # clojure-losangeles (9)
- # clojure-nl (4)
- # clojure-norway (4)
- # clojure-spec (3)
- # clojurescript (12)
- # community-development (5)
- # conjure (1)
- # core-typed (3)
- # datomic (21)
- # docker (13)
- # emacs (13)
- # funcool (1)
- # google-cloud (1)
- # graalvm (12)
- # gratitude (14)
- # holy-lambda (6)
- # introduce-yourself (18)
- # lsp (15)
- # malli (6)
- # matcher-combinators (15)
- # nbb (15)
- # off-topic (37)
- # pathom (31)
- # portal (23)
- # rdf (3)
- # releases (2)
- # reveal (2)
- # sci (4)
- # scittle (3)
- # shadow-cljs (14)
- # squint (2)
- # tools-deps (29)
In 1.0.165, it seems like this doesn't work (from the Babashka book): "Invoking a main function can be done by providing a fully qualified symbol" and then the example shows just a namespace without the main fn (specifically {:tasks {foo-bar foo.bar}}
). but when I do that I get Could not resolve symbol: my.ns
errors. but if I suffix it with /-main
it does work. is that the intended behavior? am I misreading the book?
Is it possible to support subcommands w/ exec? Seems like the cli auto-coercion drops them before they get to my main fn.
if I have a task that wraps its invoked fn in exec
and I invoke it like bb mytask sub --foo bar
currently I get args like this: ({:foo "bar"})
but if I could get something like this instead I think I'd be good to go: ("sub" {:foo "bar"})
@cap10morgan The sub
is likely on the metadata of the input map
hmm... not seeing it anywhere in the metadata of the args I get (neither the list nor the map inside it)
ah, yeah. I always do w/ -main
-main is typically called with string arguments, varargs. exec function has 1 argument, a map
ok. I looked at that metadata but didn't see it. I'll try it w/o varargs
(meta args)
still returns nil
w/o varargs
(defn -main [args]
(println "coerced args:" (pr-str args))
(println "args metadata:" (-> args meta pr-str)))
and bb.edn:
{:paths ["src"]
:deps {local/deps {:local/root "."}}
:pods {com.fluree/db {:path "../pod-fluree-db/pod-fluree-db"}}
:tasks {fdb (exec 'fluree.db.cli/-main)}}
Ah I see, the metadata gets lost due to the merge here: https://github.com/babashka/babashka/blob/bb84bd357e6bb8014b1e461a682b925839879cc8/src/babashka/impl/cli.clj#L31
while with babashka.cli.exec
the metadata is preserved since the return value of parse-opts is returned:
https://github.com/babashka/cli/blob/23f817f83046ff59a1d4ffc30c43eafec9b30bd4/src/babashka/cli/exec.clj#L59
we should probably change that "exec-fn-snippet" to match babashka.cli.exec to gain that metadata back
@cap10morgan I wondered about this myself too recently: I expected -main
not to be necessary. Perhaps something broke, not sure. Can you try with an older version of bb?
doesn't seem to work (i.e. requires /-main
) on 0.9.160, 0.8.0, nor 0.6.0
ok, yeah, that seems right. I think it's not a big deal to require /-main
as long as the docs are updated to reflect that