Skip to content

Commit

Permalink
Fix flag and Name hint
Browse files Browse the repository at this point in the history
  • Loading branch information
keynmol committed Jul 11, 2024
1 parent 9abe233 commit f241e5a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
9 changes: 6 additions & 3 deletions library.test.scala
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,13 @@ class Tests extends FunSuite:
assertArgs[Cmd](Cmd(None))()

test("argument hints: name"):
case class Cmd(@arg(_.Name("yepp")) location: Option[String])
derives CommandApplication
case class Cmd(
@arg(_.Name("yepp")) location: Option[String],
@arg(_.Name("flag2")) flag: Boolean
) derives CommandApplication

assertArgs[Cmd](Cmd(Some("shroom")))("--yepp", "shroom")
assertArgs[Cmd](Cmd(Some("shroom"), false))("--yepp", "shroom")
assertArgs[Cmd](Cmd(Some("shroom"), true))("--yepp", "shroom", "--flag2")

test("argument hints: short"):
case class Cmd(@arg(_.Short("y")) location: Option[String])
Expand Down
15 changes: 13 additions & 2 deletions macros.scala
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,20 @@ private[decline_derive] object Macros:
case '[Boolean] =>
'{
${ hints.flag } match
case None => Opts.flag($name, ${ hints.help }.getOrElse("")).orFalse
case None =>
Opts
.flag(
${ hints.name }.getOrElse($name),
${ hints.help }.getOrElse("")
)
.orFalse
case Some(value) =>
Opts.flag($name, ${ hints.help }.getOrElse("")).orTrue
Opts
.flag(
${ hints.name }.getOrElse($name),
${ hints.help }.getOrElse("")
)
.orTrue
}

case '[Option[e]] =>
Expand Down

0 comments on commit f241e5a

Please sign in to comment.