From 75365e13d12f660829c45a4e9dd0a1f6b5acb580 Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Sun, 16 Feb 2020 22:32:06 -0500 Subject: [PATCH] Add getSetting to UpperStateOps This returns Option[A]. --- main/src/main/scala/sbt/UpperStateOps.scala | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/main/src/main/scala/sbt/UpperStateOps.scala b/main/src/main/scala/sbt/UpperStateOps.scala index 897083e38..02c9ef0c3 100644 --- a/main/src/main/scala/sbt/UpperStateOps.scala +++ b/main/src/main/scala/sbt/UpperStateOps.scala @@ -33,6 +33,20 @@ trait UpperStateOps extends Any { private[sbt] def currentUnit: LoadedBuildUnit + /** + * Gets the value assigned to `key` in the computed settings map. + * If the project axis is not explicitly specified, it is resolved to be the current project according to the extracted `session`. + * Other axes are resolved to be `Zero` if they are not specified. + */ + def getSetting[A](key: SettingKey[A]): Option[A] + + /** + * Gets the value assigned to `key` in the computed settings map. + * If the project axis is not explicitly specified, it is resolved to be the current project according to the extracted `session`. + * Other axes are resolved to be `Zero` if they are not specified. + */ + def getTaskValue[A](key: TaskKey[A]): Option[Task[A]] + /** * Gets the value assigned to `key` in the computed settings map. * If the project axis is not explicitly specified, it is resolved to be the current project according to the extracted `session`. @@ -111,6 +125,10 @@ object UpperStateOps { private[sbt] def session: SessionSettings = Project.session(s) + def getSetting[A](key: SettingKey[A]): Option[A] = extract.getOpt(key) + + def getTaskValue[A](key: TaskKey[A]): Option[Task[A]] = extract.getOpt(key) + def setting[A](key: SettingKey[A]): A = extract.get(key) def taskValue[A](key: TaskKey[A]): Task[A] = extract.get(key)