Skip to content

Commit

Permalink
Conf: use Setting.allNames when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Nov 29, 2024
1 parent 5147101 commit 8346986
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
7 changes: 3 additions & 4 deletions metaconfig-core/shared/src/main/scala/metaconfig/Conf.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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: _*)
Expand Down Expand Up @@ -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) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down

0 comments on commit 8346986

Please sign in to comment.