Skip to content

Commit

Permalink
Fixed inconsistency in args parser (#2030)
Browse files Browse the repository at this point in the history
Since we support separated arguments, we first separate all arguemnts and
later valdate and extract each separated group individualy.
When we get no args at all, we create no separated groups, hence we dont
have anything to validate and we miss to create a parse error for it.

This fix instead creates an empty first separated group, so we properly
validate it and detect the case of missing args.

Pull request: #2030
  • Loading branch information
lefou authored Sep 15, 2022
1 parent 1803cb5 commit d5a14a8
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion main/core/src/mill/define/ParseArgs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ object ParseArgs {
*/
@tailrec
def separated(result: Seq[Seq[String]], rest: Seq[String]): Seq[Seq[String]] = rest match {
case Seq() => result
case Seq() => if (result.nonEmpty) result else Seq(Seq())
case r =>
val (next, r2) = r.span(_ != TargetSeparator)
separated(
Expand Down
1 change: 1 addition & 0 deletions main/test/src/util/ParseArgsTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ object ParseArgsTest extends TestSuite {
def parsed(args: String*) = ParseArgs(args, selectMode)
test("rejectEmpty") {
assert(parsed("") == Left("Selector cannot be empty"))
assert(parsed() == Left("Selector cannot be empty"))
}
def check(
input: Seq[String],
Expand Down

0 comments on commit d5a14a8

Please sign in to comment.