Skip to content

The :collect feature eats all remaining arguments #122

@Ramblurr

Description

@Ramblurr

Problem

I'd like to use babashka.cli to parse a cli string where an option can be passed multiple times and likewise also having multiple positional arguments.

Example

(cli/parse-args ["--foo" "a,b" "--foo" "c" "arg1" "arg2"]
                   {:coerce     {:foo         []
                                 :positionals []}
                    :args->opts (repeat :positionals)
                    :collect    {:foo (fn [coll arg-value]
                                        (into (or coll [])
                                              (str/split arg-value #",")))}})
;; => {:opts {:foo ["a" "b" "c" "arg1" "arg2"]}}

But I would expect

{:opts {:foo ["a" "b" "c"] :positionals ["arg1" "arg2"]}}

It seems that the :collect feature is eating all of the remaining arguments:

(cli/parse-args ["--foo" "a" "arg1" "arg2"] ...)
;; => {:opts {:foo ["a" "arg1" "arg2"]}}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions