Clap: Multiple values separated by a delimiter _only_?

Created on 28 Jun 2016  路  6Comments  路  Source: clap-rs/clap

I'm trying to make an arg that accepts one or two comma-delimited values, and also accept unnamed (index) argument after that.

prog -q 1,2 file # OK: parses as q=[1,2]; input=file
prog -q 1 file # should parse as q=[1]; input=file; but parses as q=[1,file]; input missing

The problem is that multiple arguments allow spaces, which causes ambiguity. I don't know how to disable that.

parsing medium nice to have RFC / question bug 2.x

All 6 comments

Currently, there isn't a way to _force_ the use of a delimiter. That is something that could be added.

But there are few other things about this scenario too: Is there a limit on the number of values for q? Otherwise, prog -q 1,2 file won't parse like q=[1,2]; input=file

I could consider this a bug, so-to-speak. i.e. if a delimiter is present, parsing something after a space probably shouldn't be part of the same value group. This still doesn't help your scenario 2 though. To go along with the above "bug" is parsing something like -q=1 file shouldn't lump file in with -q, but currently does.

So, would solving those two bugs suffice, or would a force_delimiter still be preferred? i.e.

  • if a delimiter is present, don't parse anything after a space as the same group of values
  • if a = is present, don't parse anything after a space as the same group of values

This would allow you to do -q=1 file and the option of either -q 1,2 file or -q=1,2 file all parsing correctly.

My only issue with the require_delimiter type thing, is it seems somewhat niche assuming the above bugs are fixed. I would assume most people, upon realizing -q 1 file isn't working would try -q=1 file next.

Edit: thinking about it more, I'm good adding the require_delimiter, but still want some thoughts on the matter :)

Thank you for your response.

In my case it's strictly 1 or 2 values for q. require_delimiter would be ideal for me, as -q 1 file case is going to be the most common in my program.

547 implements those two bug fixes and will be uploaded to crates.io as v2.7.1, then I'll add the Arg::require_delimiter in a new PR and upload as v2.8.0 to crates.io to keep all SemVer users aware of changes.

Fantastic! Thank you!

Arg::require_delimiter isn't implemented yet, doing so now :wink:

I want to keep this open just a tracking issue for that, until the PR merges.

This will be fully implemented with #551

Was this page helpful?
0 / 5 - 0 ratings

Related issues

artemshein picture artemshein  路  4Comments

lilianmoraru picture lilianmoraru  路  4Comments

laishulu picture laishulu  路  3Comments

AlexanderThaller picture AlexanderThaller  路  5Comments

BurntSushi picture BurntSushi  路  5Comments