3

My program takes several file names as command line arguments, for example:

./myProgram -F file1 file2

This simple case works fine with Clap, in fact it's the doc example of Arg::multiple().

However, I'd also like each file to take arguments of its own, which changes the behavior of that particular file. Simplified example:

./myProgram -F --name file1 ---format csv --priority 2 -F --name file2 --priority 1

Here, file1 has a higher priority and a different format from file2.

Simply using Arg::multiple() no longer works, since the file-specific arguments (format, priority) get parsed as independent arguments, with no way to know which file they belong to.

Arg::allow_hyphen_values() seems to get me part of the way there. But it just parses every occurrence of --name, file1, --format etc as a value to the -F option, with no way to know which --priority argument belongs to which file. I thought about using a different syntax for the file specific arguments and parsing those manually, but with this restriction, I can't even do that.

Is there any way to to do this with Clap?

Morten Lohne
  • 383
  • 2
  • 11

0 Answers0