-
Notifications
You must be signed in to change notification settings - Fork 21
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
Allow short arguments and flags to be combined #102
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice feature. And since we preserved the binary compatibility, we can use it in Mill right away. I'm looking forward for working mill -Denv=var
support (without the space after -D
), which popped up in the support channels more than once.
@lefou as implemented, I think we can make it work by specifying that Do you think we should do that? Should be an easy change if we want it |
Oh, than I misread it. What's the difference between Anyways, I find properties like being able to combine short no-arg options ( |
How about So either |
I updated the PR to allow As specified, it also means |
@lefou ok I think I got it working. take a look at the update to I think this handles most cases in a reasonably intuitive manner; the only bit of weirdness is that |
Notably, our treatment of combined multiple-short-flags-and-argument-values matches some existing tools like Git: $ git commit -am.
[test f25b226a55] .
$ git commit -ma. --allow-empty
[test d71b21942f] a. Note how |
This was accidentally broken in #102 and #112, and wasn't covered by tests. Noticed when trying to update Ammonite to the latest version of MainArgs in com-lihaoyi/Ammonite#1549 Restored the special casing for tracking/handling incomplete arguments and added some unit test cases
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 liketar tfv <file>
wheref
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 futureCovered by additional unit tests