These are chat archives for kbknapp/clap-rs

13th
Oct 2017
Tassilo Horn
@tsdh
Oct 13 2017 20:29
Hi all! Does clap provide some finished solution for arguments which may occur multiple times and the order of arguments is significant?
Like: mytool --match this --select those --match that --select these
where the "those" would refer to the matches of "this" and "these" to those of "that"
Kevin K.
@kbknapp
Oct 13 2017 20:32
Yes and no. The order of values is preserved, but not the order of interleaved flags. I.e. the values of "match" would be "this, that" and the values of "select" would be "those, these"
If the user did, "--match this --match that --select those --select these" it'd be the same result.
Tassilo Horn
@tsdh
Oct 13 2017 20:34
I see.
Kevin K.
@kbknapp
Oct 13 2017 20:34
Someone else asked for something similar, so I'm not opposed to adding it
But I'd need some ideas on how that'd used
Or in the perfect world how do you invision it working
I'm on mobile too...so please forgive short answers :P
Tassilo Horn
@tsdh
Oct 13 2017 20:38
I'm just toying around with rust and thought I write some grep-like utility for CSV files where I could do "mygrep --separator ';' --match 3='foo.*' --select 1,2,5 myfile.csv" and that would match all rows of the semicolon-separated values file where the third cell of the row starts with foo and print the 1st, 2nd, and 5th cell of the row.
So there could be many --match clauses, and the following --select should consider only those rows matched by the preceding --match.
So I'd be happy if there was some method values_iter("match", "select") which would provide an iterator over all values provided to --match and --select in the order they were specified. Or something like that...
Kevin K.
@kbknapp
Oct 13 2017 20:42
So long as there is always a 1:1 for --match:--select you either solve it in user code (match[0]:select[0])
Tassilo Horn
@tsdh
Oct 13 2017 20:43
I guess --select is optional where not provided means select all cells.
Kevin K.
@kbknapp
Oct 13 2017 20:43
Clap does support enforcing the 1:1 of those args
Aah ok
Yeah then a --match --select --match --match --select would be an issue
Tassilo Horn
@tsdh
Oct 13 2017 20:46
With (match[0]:select[0]) you meant iterating with index over the values of match and select, right? Just to make sure that I'm following and you are not writing some nifty rust syntax I haven't encountered yet.
Kevin K.
@kbknapp
Oct 13 2017 20:49
Yep exactly! Sorry yeah that would be cool, but I just meant indexing
Tassilo Horn
@tsdh
Oct 13 2017 20:54
Ok, thanks a lot for now. Gotta go to bed cause tomorrow is theme park day with the kids. :-)
Kevin K.
@kbknapp
Oct 13 2017 21:00
No worries and no problem! I know how that is myself :)