Skip to content
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

Add BigDecimal TokensReader #152

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions mainargs/src/TokensReader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ object TokensReader {
def shortName = "double"
def read(strs: Seq[String]) = tryEither(strs.last.toDouble)
}
implicit object BigDecimalRead extends Simple[BigDecimal] {
def shortName = "bigdecimal"
def read(strs: Seq[String]) = tryEither(BigDecimal(strs.last))
}

implicit def LeftoverRead[T: TokensReader.Simple]: TokensReader.Leftover[mainargs.Leftover[T], T] =
new LeftoverRead[T]()(implicitly[TokensReader.Simple[T]])
Expand Down
20 changes: 16 additions & 4 deletions mainargs/test/src/ManyTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ object ManyTests extends TestSuite {
i: Boolean,
j: String,
k: Int,
l: Boolean
l: Boolean,
m: Double,
n: BigDecimal
)

val parser = ParserForClass[Config]
Expand Down Expand Up @@ -46,7 +48,11 @@ object ManyTests extends TestSuite {
"--k",
"4",
"--l",
"false"
"false",
"--m",
"5.50",
"--n",
"12345678901234567890.12345678901234567890"
),
allowPositional = true
)
Expand All @@ -73,7 +79,11 @@ object ManyTests extends TestSuite {
"--k",
"4",
"--l",
"false"
"false",
"--m",
"5.50",
"--n",
"12345678901234567890.12345678901234567890"
),
allowPositional = true
)
Expand Down Expand Up @@ -115,7 +125,9 @@ object ManyTests extends TestSuite {
"true",
"J",
"4",
"false"
"false",
"5.50",
"12345678901234567890.12345678901234567890"
),
allowPositional = true
)
Expand Down