mainargs icon indicating copy to clipboard operation
mainargs copied to clipboard

short args should be parsed when there is no space after

Open vobloeb opened this issue 4 years ago • 6 comments

for example

@main
def ooo(@arg(short = 'j') concurrency: Int=1, vals: Leftover[String]): Unit = {
}

should allow -j16 as -j 16.

currently -j16 goes to leftover

vobloeb avatar Feb 23 '21 14:02 vobloeb

How would you distinguish between this and the other kind of short args that can be chained together, e.g. tar -xzvf? Perhaps we'd need a configuration flag or something the same way we have allowPositional=true?

lihaoyi avatar Dec 09 '21 11:12 lihaoyi

In the OP example -j16, after detecting the -j option, we could try to find an option matching -1, and fall back to parsing the rest string ("16") as argument, when appropriate. We should provide an option to disable this parsing behavior though.

lefou avatar Jan 10 '22 11:01 lefou

How would you distinguish between this and the other kind of short args that can be chained together, e.g. tar -xzvf? Perhaps we'd need a configuration flag or something the same way we have allowPositional=true?

It's a good question. I looked at two standard programs that do similar things. git log -Stest is valid, so short flags arguments work without a space, but git log -gt is not, so it doesn't allow combining short flags at all.

On the other hand, grep supports both:

$ echo | grep -iwftest test                                                                                                                                       
grep: test: No such file or directory

So I guess what grep does is that short flags that take an argument (I would imagine even an optional one) terminate parsing for more short flags. So an argument-less short flag can be followed by another short flag letter of any type, or whitespace.

nafg avatar Jan 11 '22 05:01 nafg

In tar you can give tar xfz <file> where <file> is the actual argument to f.

lefou avatar Feb 02 '22 15:02 lefou

tar is very nonstandard and the subject of plenty of internet commentary

nafg avatar Feb 02 '22 18:02 nafg

Sorry I think I misunderstood your point.

A space should be allowed, but at least when the flag is on its own it should be optional.

nafg avatar Feb 02 '22 18:02 nafg