Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

short args should be parsed when there is no space after #7

Closed
kvtb opened this issue Feb 23, 2021 · 8 comments · Fixed by #102
Closed

short args should be parsed when there is no space after #7

kvtb opened this issue Feb 23, 2021 · 8 comments · Fixed by #102
Milestone

Comments

@kvtb
Copy link

kvtb commented Feb 23, 2021

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

@lihaoyi
Copy link
Member

lihaoyi commented Dec 9, 2021

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?

@lefou
Copy link
Member

lefou commented Jan 10, 2022

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.

@nafg
Copy link

nafg commented Jan 11, 2022

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.

@lefou
Copy link
Member

lefou commented Feb 2, 2022

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

@nafg
Copy link

nafg commented Feb 2, 2022

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

@nafg
Copy link

nafg commented Feb 2, 2022

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.

@lefou
Copy link
Member

lefou commented Feb 14, 2023

What I wanted to demonstrate is that we could accept also combined short-options which accept itself arguments. For example the args -x -f <file> -z could also be given as -xfz <file>.

@nafg
Copy link

nafg commented Feb 14, 2023 via email

lihaoyi added a commit that referenced this issue Jan 26, 2024
Fixes #7

This PR allows flags like `-abtrue` to mean `-a -b true`, by walking the
combined flag one character at a time and seeing if each character is a
flag that takes zero values, or a non-flag argument that takes one
value, which is set to the remaining part of the combined flag (in the
case above, `"true"`). This allows some nice shorthands, like `./mill
-wk -j10` rather than `./mill -w -k -j 10`

This is the only way I could find that allows both combining multiple
flags like `-ab`, and combining flags with values like `-btrue`. Trying
to handle more sophisticated cases like `tar tfv <file>` where `f` is
given `<file>` is fundamentally incompatible, and would need some
user-facing configuration to enable.

Combining multiple short arguments together with gflags `=` syntax, e.g.
`-ab=true`, is currently not allowed. This follows the current
limitation where we do not allow single short args to be used with `=`,
e.g. `-f=bar` is prohibited. In general, combined short arguments are
not allowed to have `=` in it. If you want the `=` to be part of the
value, you can move it into a separate token e.g. `-ab =true`

For now, this improvement can be done fully transparently and
backwards-compatibly without any need for user opt-in or configuration,
and should cover the 99% use case. There is no conflict with existing
long arguments, as those currently require two dashes `--`, and so a
multi-character token starting with a single `-` is currently
disallowed. Adding additional flexibility and configuration can come
later future

Covered by additional unit tests
@lefou lefou added this to the 0.6.0 milestone Jan 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants