This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-07-27
Channels
- # babashka (35)
- # beginners (85)
- # cider (14)
- # clojure (115)
- # clojure-europe (15)
- # clojure-norway (2)
- # clojure-portugal (9)
- # clojure-uk (3)
- # clojurescript (28)
- # conjure (35)
- # data-science (10)
- # datomic (4)
- # graalvm (28)
- # holy-lambda (7)
- # hyperfiddle (2)
- # jobs (2)
- # joker (4)
- # malli (9)
- # meander (6)
- # nbb (6)
- # off-topic (23)
- # pathom (3)
- # remote-jobs (1)
- # shadow-cljs (158)
- # sql (15)
- # tools-deps (35)
- # vim (5)
Taking #babashka-cli to the next step by integrating it with babashka. Proposal: https://github.com/babashka/babashka/issues/1324

@UE21H2HHD Do you have any ideas on what that might look like?
Sorry, had not given it much thought, but I do seem to like a cli that validates args and provides usage help.
The philosophy behind babashka CLI is that you would turn a function into a CLI. If you validate args when doing a CLI invocation, why should this validate and not when you invoke the function from a REPL?
I'm just echoing one argument here, please change my mind, I'm curious to hear your thoughts
Ya, that's certainly a reasonable argument. I do like a consistent way of validating args and presenting usage help. I currently often use docopt these days, it is not perfect (I sometimes spin my wheels figuring out how to express things) but it helps with these goals.
Maybe I'm focusing on classic command line usage/validation/help. This might not be something babashka-cli wants to concern itself with.
Maybe provide a helper to format malli schema validation errors in a "CLI appropriate form"?
@U3JH98J4R bb CLI has no dependency on malli / spec / schema
But just throwing an error with a configurable message upon the first failure seems reasonable
:validate [#(< 0 % 0x10000) "Must be a number between 0 and 65536"]]
:validate [#(< 0 % 0x10000) #(str % " is not a number between 0 and 65536")]
instead of a tuple, we could have :validate
be a function which receives a map
:validate {:fn #{:foo :bar} :error-fn (fn [{:keys [opt]}] {:message (str "O no!!!! opt")})
or soBut it seems you could do this fairly easily yourself after the options have been passed to the function
I don't understand why you would only throw on CLI invocation but give fn invocation from the REPL a free pass
I guess parse-args can return :errors
thing, like tools.cli does:
If the validation-fn returns a falsey value, the validation-msg is added to the errors vector.
I thinking it might be a matter of usage perspective.
If as a user you know you are using babashka-cli as a way to invoke a Clojure function from the command line, you might be just fine with a stack trace as an error, and then having to look at a docstring and/or source for proper usage.
If as a user you see yourself as using a command line tool, you expectations will likely be different. The Clojure fn being called is an implementation detail. You likely expect some --help
or help
option to be available, and likely expect textual error and/or usage help when you specify invalid input. When I write babashka tasks, I see myself as writing command line tools, so I (usually) try to make them follow the general conventions of command line tools.
So it's a disjoint task, I don't think babashka needs to support it so much as "map->CLI conventions" is a task people will want to do
the bb -x foo/bar --dude
case should then also handle the :errors
if there are some, print those and exit with 1
posted an idea here: https://github.com/babashka/cli/issues/31
I'm using babashka-cli, and just note that I expect the returned options map to use the long key (i.e. :pretty) rather than the short alias key (e.g., :p). Maybe I'm late to the discussion, but this is also more in line with clojure.tools.cli does.
@U04VDKC4G Let's go to #babashka-cli