Skip to content

Commit

Permalink
opts
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude committed Jan 2, 2024
1 parent 0d50507 commit f5f3b37
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,35 @@ Additional `parse-arg` options may be passed in each table entry:
{:cmds [] :fn help}])
```

### Shared options

Since cli 0.8.54, babashka.cli supports parsing shared options in between and before the subcommands.

E.g.:

``` clojure
(def global-spec {:foo {:coerce :keyword}})
(def sub1-spec {:bar {:coerce :keyword}})
(def sub2-spec {:baz {:coerce :keyword}})

(def table
[{:cmds [] :spec global-spec}
{:cmds ["sub1"] :fn identity :spec sub1-spec}
{:cmds ["sub1" "sub2"] :fn identity :spec sub2-spec}])

(cli/dispatch table ["--foo" "a" "sub1" "--bar" "b" "sub2" "--baz" "c" "arg"])

;;=>

{:dispatch ["sub1" "sub2"],
:opts {:foo :a, :bar :b, :baz :c},
:opts-by-cmds
[{:cmds [], :opts {:foo :a}}
{:cmds ["sub1"], :opts {:bar :b}}
{:cmds ["sub1" "sub2"], :opts {:baz :c}}],
:args ["arg"]}
```

## Babashka tasks

For documentation on babashka tasks, go
Expand Down

0 comments on commit f5f3b37

Please sign in to comment.