From f241e5a3eb996ce1272c8ec78d0e1041ac5af3b6 Mon Sep 17 00:00:00 2001 From: Anton Sviridov Date: Thu, 11 Jul 2024 22:25:27 +0100 Subject: [PATCH] Fix flag and Name hint --- library.test.scala | 9 ++++++--- macros.scala | 15 +++++++++++++-- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/library.test.scala b/library.test.scala index 701c5b5..d4eaf3c 100644 --- a/library.test.scala +++ b/library.test.scala @@ -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]) diff --git a/macros.scala b/macros.scala index 684f7f8..e14995b 100644 --- a/macros.scala +++ b/macros.scala @@ -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]] =>