Skip to content

Commit

Permalink
Support custom name formatter when using withHelp (#188)
Browse files Browse the repository at this point in the history
  • Loading branch information
regadas authored Mar 16, 2020
1 parent 85e378a commit c276486
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ abstract class Parser[T] {
*/
final def withHelp: Parser[WithHelp[T]] = {
implicit val parser: Parser.Aux[T, D] = this
val p = Parser[WithHelp[T]]
val p = ParserWithNameFormatter(Parser[WithHelp[T]], defaultNameFormatter)
if (defaultStopAtFirstUnrecognized)
p.stopAtFirstUnrecognized
else
Expand Down
16 changes: 16 additions & 0 deletions tests/shared/src/test/scala/caseapp/Tests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,22 @@ object Tests extends TestSuite {
assert(res == expectedRes)
}

"parser withHelp works with custom option formatter" - {
val res =
Parser[FewArgs]
.nameFormatter((n: Name) => n.name)
.withHelp
.detailedParse(
Seq("--value", "b", "--numFoo", "1")
)

val expectedRes =
Right(
(WithHelp(false, false, Right(FewArgs("b", 1))), RemainingArgs(List(), List()))
)
assert(res == expectedRes)
}

}

}

0 comments on commit c276486

Please sign in to comment.