These are chat archives for kbknapp/clap-rs

25th
May 2018
Marcus Ewert
@sarum90
May 25 2018 14:43

Hey all!

I've got what I hope is a quick question.

I'm trying to port an existing command line API to CLAP-rs, and the current implementation uses a sort of state machine as it parses arguments, such that the flags change what they mean depending on their surrounding flags.

A contrived example would be:

./foobar --file test1 --file-type CSV --file test2 --file-type TSV --file test3 --file test4 --file-type XML

where --file-type is optional (defaults to newline deliminated JSON) and modifies the previous --file argument

So the above example would parse

  • test1 as CSV
  • test2 as TSV
  • test3 as DEFAULT (newline deliminated JSON)
  • test4 as XML

I thought this might be what "groups" would be used for, but that appears to be a different concept.

Is there a good way to map this sort of API into CLAP-rs? If so, could someone point me to the right part of the documentation to look at? I was contemplating using a custom validator, but that seems pretty hacky, and would assume that CLAP-rs always calls validators in left to right order, which I'm not sure is guaranteed.