Skip to content

Commit

Permalink
SectionRename: no curried arg lists in annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Dec 11, 2024
1 parent ab486a3 commit 9ab786a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ final case class TabCompleteAsPath() extends StaticAnnotation
final case class CatchInvalidFlags() extends StaticAnnotation
final case class TabCompleteAsOneOf(options: String*) extends StaticAnnotation

final case class SectionRename(oldName: String, newName: String)(
val conv: PartialFunction[Conf, Conf] = PartialFunction.empty,
final case class SectionRename(
oldName: String,
newName: String,
conv: PartialFunction[Conf, Conf] = PartialFunction.empty,
) extends StaticAnnotation {
require(oldName.nonEmpty && newName.nonEmpty)
val oldNameAsSeq: Seq[String] = ArraySeq.unsafeWrapArray(oldName.split('.'))
Expand All @@ -47,6 +49,10 @@ final case class SectionRename(oldName: String, newName: String)(
s"Section '$oldName' is deprecated and renamed as '$newName'"
}
object SectionRename {
def apply(
conv: PartialFunction[Conf, Conf],
)(oldName: String, newName: String): SectionRename =
new SectionRename(oldName, newName, conv)
implicit def fromTuple(obj: (String, String)): SectionRename =
SectionRename(obj._1, obj._2)()
SectionRename(obj._1, obj._2)
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,14 @@ class DeriveConfDecoderExJVMSuite extends munit.FunSuite {

test("nested param with rename 2") {
implicit val nested2: ConfDecoderEx[Nested2] = generic
.deriveDecoderEx(Nested2()).noTypos
.withSectionRenames(SectionRename("B", "b") { case Conf.Obj(vals) =>
Conf.Obj(vals.map {
case ("param", Conf.Num(v)) => "param" -> Conf.Num(v * 2)
case x => x
})
})
.deriveDecoderEx(Nested2()).noTypos.withSectionRenames(
SectionRename { case Conf.Obj(vals) =>
Conf.Obj(vals.map {
case ("param", Conf.Num(v)) => "param" -> Conf.Num(v * 2)
case x => x
})
}("B", "b"),
)
implicit val nested3: ConfDecoderEx[Nested3] = generic
.deriveDecoderEx(Nested3()).noTypos
val nested: ConfDecoderEx[Nested] = generic.deriveDecoderEx(Nested())
Expand Down

0 comments on commit 9ab786a

Please sign in to comment.