From 206c3e6d4d3b07824a8f4f8eada2eccc853c6fc6 Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Mon, 27 Feb 2017 14:31:15 +0000 Subject: [PATCH] Introduce Def displayBuildRelative/showBuildRelativeKey --- main-settings/src/main/scala/sbt/Def.scala | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/main-settings/src/main/scala/sbt/Def.scala b/main-settings/src/main/scala/sbt/Def.scala index 7f08e50bb..18062bb71 100644 --- a/main-settings/src/main/scala/sbt/Def.scala +++ b/main-settings/src/main/scala/sbt/Def.scala @@ -4,6 +4,7 @@ import sbt.internal.util.Types.const import sbt.internal.util.{ Attributed, AttributeKey, Init, Show } import sbt.internal.util.complete.Parser import java.io.File +import java.net.URI import Scope.{ ThisScope, GlobalScope } import KeyRanks.{ DTask, Invisible } @@ -26,12 +27,21 @@ object Def extends Init[Scope] with TaskMacroExtra { def apply(key: ScopedKey[_]) = Scope.display(key.scope, colored(key.key.label, keyNameColor), ref => displayRelative(current, multi, ref)) } + def showBuildRelativeKey(currentBuild: URI, multi: Boolean, keyNameColor: Option[String] = None): Show[ScopedKey[_]] = new Show[ScopedKey[_]] { + def apply(key: ScopedKey[_]) = + Scope.display(key.scope, colored(key.key.label, keyNameColor), ref => displayBuildRelative(currentBuild, multi, ref)) + } def displayRelative(current: ProjectRef, multi: Boolean, project: Reference): String = project match { case BuildRef(current.build) => "{.}/" case `current` => if (multi) current.project + "/" else "" case ProjectRef(current.build, x) => x + "/" case _ => Reference.display(project) + "/" } + def displayBuildRelative(currentBuild: URI, multi: Boolean, project: Reference): String = project match { + case BuildRef(`currentBuild`) => "{.}/" + case ProjectRef(`currentBuild`, x) => x + "/" + case _ => Reference.display(project) + "/" + } def displayFull(scoped: ScopedKey[_]): String = displayFull(scoped, None) def displayFull(scoped: ScopedKey[_], keyNameColor: Option[String]): String = Scope.display(scoped.scope, colored(scoped.key.label, keyNameColor)) def displayMasked(scoped: ScopedKey[_], mask: ScopeMask): String = Scope.displayMasked(scoped.scope, scoped.key.label, mask)