From 83469864b7e38ddb267e02cab1634e0bb9cd797c Mon Sep 17 00:00:00 2001 From: Albert Meltzer <7529386+kitbellew@users.noreply.github.com> Date: Fri, 29 Nov 2024 07:09:08 -0800 Subject: [PATCH] Conf: use Setting.allNames when possible --- .../shared/src/main/scala/metaconfig/Conf.scala | 7 +++---- .../src/main/scala/metaconfig/internal/ConfGet.scala | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/metaconfig-core/shared/src/main/scala/metaconfig/Conf.scala b/metaconfig-core/shared/src/main/scala/metaconfig/Conf.scala index f5dbef6b..945d86ab 100644 --- a/metaconfig-core/shared/src/main/scala/metaconfig/Conf.scala +++ b/metaconfig-core/shared/src/main/scala/metaconfig/Conf.scala @@ -28,13 +28,12 @@ sealed abstract class Conf extends Product with Serializable { def getSettingOrElse[T: ConfDecoder]( setting: Setting, default: T, - ): Configured[T] = ConfGet - .getOrElse(this, default, setting.name, setting.alternativeNames: _*) + ): Configured[T] = ConfGet.getOrElse(this, default, setting.allNames) def get[T: ConfDecoder](path: String, extraNames: String*): Configured[T] = ConfGet.get(this, path, extraNames: _*) def getOrElse[T: ConfDecoder](path: String, extraNames: String*)( default: T, - ): Configured[T] = ConfGet.getOrElse(this, default, path, extraNames: _*) + ): Configured[T] = ConfGet.getOrElse(this, default, path +: extraNames) def getNested[T: ConfDecoder](keys: String*): Configured[T] = ConfGet .getNested(this, keys: _*) @@ -120,7 +119,7 @@ object Conf { state: A, conf: Conf, setting: Setting, - ): Configured[A] = getEx(state, conf, setting.name +: setting.alternativeNames) + ): Configured[A] = getEx(state, conf, setting.allNames) implicit class ConfImplicit(conf: Conf) { diff --git a/metaconfig-core/shared/src/main/scala/metaconfig/internal/ConfGet.scala b/metaconfig-core/shared/src/main/scala/metaconfig/internal/ConfGet.scala index a67f29ed..427f72ee 100644 --- a/metaconfig-core/shared/src/main/scala/metaconfig/internal/ConfGet.scala +++ b/metaconfig-core/shared/src/main/scala/metaconfig/internal/ConfGet.scala @@ -25,10 +25,9 @@ object ConfGet { case None => None } - def getOrElse[T](conf: Conf, default: T, path: String, extraNames: String*)( - implicit ev: ConfDecoder[T], - ): Configured[T] = getKey(conf, path +: extraNames) - .fold(Configured.ok(default))(ev.read) + def getOrElse[T](conf: Conf, default: T, keys: Seq[String])(implicit + ev: ConfDecoder[T], + ): Configured[T] = getKey(conf, keys).fold(Configured.ok(default))(ev.read) def get[T](conf: Conf, path: String, extraNames: String*)(implicit ev: ConfDecoder[T],