Search code examples
rustclap

Is it possible to configure argument groups of unknown size with Clap?


I'm building a CLI which can call other underlying programs, that have their own options and arguments. I'd like to be able to pass those options to a program through the CLI.

$ cli --program [PROGRAM] --programOpts[OPT1, OPT2, ...]

Example:

$ cli --program foo --programOpts.bar 'foo' --programOpts.foo 'bar'

^ In this case bar and foo in programOpts are unknown to cli. The CLI only knows about programOpts and that it's an unknown vector of options specific to the underlying program that's being called.

I was hoping Clap had an API to implement such a thing (looked into Arg and ArgGroup) but it doesn't seem like it.

Is there such an API?


Solution

  • After further research I decided to go down a slightly different path and rather take advantage of the known UNIX -- syntax.

    Meaning that all options and flags coming after -- will be passed down to the underlying program:

    $ cli --program [PROGRAM] -- foo bar --bazinga --yay=w00t
    

    This can be done using Clap's .raw() configuration on Arg structs.