Skip to content

Commit

Permalink
Merge pull request #304 from alexarchambault/develop
Browse files Browse the repository at this point in the history
Tweaking
  • Loading branch information
alexarchambault authored Jun 17, 2021
2 parents 704bc93 + bf5a112 commit efc89db
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion core/shared/src/main/scala/caseapp/core/complete/Zsh.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ object Zsh {
if (arguments.isEmpty) Nil
else {
val desc = item.description.map(":" + _.replace("'", "\\'")).getOrElse("")
arguments.map("'" + _ + desc + "'")
arguments.map("'" + _.replace(":", "\\:") + desc + "'")
}
optionsOutput ++ argumentsOutput
}
Expand Down
4 changes: 3 additions & 1 deletion core/shared/src/main/scala/caseapp/core/parser/Parser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ abstract class Parser[T] {
}
val reverseSteps0 = Step.DoubleDash(index) :: reverseSteps.reverse
(res, reverseSteps0.reverse)
case opt :: rem if opt.startsWith("-") =>
case opt :: rem if opt.startsWith("-") && opt != "-" =>
if (ignoreUnrecognized)
helper(current, rem, opt :: extraArgsReverse, Step.IgnoredUnrecognized(index) :: reverseSteps, index + 1)
else if (stopAtFirstUnrecognized) {
Expand Down Expand Up @@ -282,6 +282,8 @@ abstract class Parser[T] {
completer.optionName(value, stateOpt)
case Step.Unrecognized(_, _) =>
completer.optionName(value, stateOpt)
case Step.StandardArgument(idx) if args0(idx) == "-" =>
completer.optionName(value, stateOpt)
case Step.MatchedOption(_, consumed, arg) if shift == 0 =>
completer.optionName(value, stateOpt)
case Step.MatchedOption(_, consumed, arg) if consumed == 2 && shift == 1 =>
Expand Down
21 changes: 21 additions & 0 deletions tests/shared/src/test/scala/caseapp/ParserTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ object ParserTests extends TestSuite {
NilParser
val res = parser.to[Helper].parse(Seq("-n", "2", "something", "--value", "foo"))
val expected = Right((Helper(2, "foo"), Seq("something")))
assert(res == expected)
}
test("tuple") {
case class Helper(n: Int, value: String)
Expand All @@ -24,6 +25,7 @@ object ParserTests extends TestSuite {
NilParser
val res = parser.toTuple.parse(Seq("-n", "2", "something", "--value", "foo"))
val expected = Right(((2, "foo"), Seq("something")))
assert(res == expected)
}
test("default value") {
case class Helper(n: Int, value: String)
Expand All @@ -34,15 +36,34 @@ object ParserTests extends TestSuite {
test {
val res = parser.to[Helper].parse(Seq("-n", "2", "something", "--value", "foo"))
val expected = Right((Helper(2, "foo"), Seq("something")))
assert(res == expected)
}
test {
val res = parser.to[Helper].parse(Seq("-n", "2", "something"))
val expected = Right((Helper(2, "-"), Seq("something")))
assert(res == expected)
}
test {
val res = parser.to[Helper].parse(Seq("--value", "other", "something"))
assert(res.isLeft)
}
}
test("Keep single dashes in user arguments") {
case class Helper(n: Int, value: String)
val parser =
Argument[Int](Arg("n")) ::
Argument[String](Arg("value")).withDefault(() => Some("default")) ::
NilParser
test("single") {
val res = parser.to[Helper].parse(Seq("-n", "2", "-"))
val expected = Right((Helper(2, "default"), Seq("-")))
assert(res == expected)
}
test("several") {
val res = parser.to[Helper].parse(Seq("-", "a", "-", "-n", "2", "-"))
val expected = Right((Helper(2, "default"), Seq("-", "a", "-", "-")))
assert(res == expected)
}
}
}
}

0 comments on commit efc89db

Please sign in to comment.