You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
…#66)
Should fix#58 and
#60
Previously, we allowed any arg to take positional arguments if
`allowPositional = true` (which is the case for Ammonite and Mill
user-defined entrypoints.), even `mainargs.Flag`s. for which being
positional doesn't make sense.
```scala
val positionalArgSigs = argSigs
.filter {
case x: ArgSig.Simple[_, _] if x.reader.noTokens => false
case x: ArgSig.Simple[_, _] if x.positional => true
case x => allowPositional
}
```
The relevant code path was rewritten in
#62, but the buggy behavior
was preserved before and after that change. This wasn't caught in other
uses of `mainargs.Flag`, e.g. for Ammonite/Mill's own flags, because
those did not set `allowPositional=true`
This PR tweaks `TokenGrouping.groupArgs` to be more discerning about how
it selects positional, keyword, and missing arguments:
1. Now, only `TokenReader.Simple[_]`s with `.positional` or
`allowPositional` can be positional; `Flag`s, `Leftover`, etc. cannot
2. Keyword arguments are limited only to `Flag`s and `Simple` with
`!a.positional`
Added `mainargs.IssueTests.issue60` as a regression test, that fails on
main and passes on this PR. Existing tests all pass
I'm using mainargs in ammonite, but the result is not correct.
code
case 1
amm bug.sc --str str a b c d
expected:
actual:
case 2
amm bug.sc a b c d
expected:
actual:
The text was updated successfully, but these errors were encountered: