diff --git a/metaconfig-core/shared/src/main/scala/metaconfig/annotation/Annotations.scala b/metaconfig-core/shared/src/main/scala/metaconfig/annotation/Annotations.scala index fb26f97..c356a7b 100644 --- a/metaconfig-core/shared/src/main/scala/metaconfig/annotation/Annotations.scala +++ b/metaconfig-core/shared/src/main/scala/metaconfig/annotation/Annotations.scala @@ -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('.')) @@ -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) } diff --git a/metaconfig-tests/jvm/src/test/scala/metaconfig/DeriveConfDecoderExJVMSuite.scala b/metaconfig-tests/jvm/src/test/scala/metaconfig/DeriveConfDecoderExJVMSuite.scala index 5981a43..178a521 100644 --- a/metaconfig-tests/jvm/src/test/scala/metaconfig/DeriveConfDecoderExJVMSuite.scala +++ b/metaconfig-tests/jvm/src/test/scala/metaconfig/DeriveConfDecoderExJVMSuite.scala @@ -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())