Transition to all camelCase key labels.

1. Hyphenated labels are still accepted when parsing scoped keys (so 'sbt test-only' still works)
   There is currently no timeline for removing this support for hyphenated keys.
2. Only camelCase is shown for tab completion.
3. AttributeKey.rawLabel provides the unnormalized label.
   This should only be used to implement support for accepting hyphenated keys as input for compatibility.
4. AttributeKey.normLabel provides the normalized label (hyphenated converted to camelCase)
This commit is contained in:
Mark Harrah 2012-11-13 14:52:33 -05:00
parent ed41547a47
commit 237b80eb22
2 changed files with 13 additions and 3 deletions

View File

@ -11,6 +11,8 @@ import scala.reflect.Manifest
// a single AttributeKey instance cannot conform to AttributeKey[T] for different Ts
sealed trait AttributeKey[T] {
def manifest: Manifest[T]
@deprecated("Should only be used for compatibility during the transition from hyphenated labels to camelCase labels.", "0.13.0")
def rawLabel: String
def label: String
def description: Option[String]
def extend: Seq[AttributeKey[_]]
@ -48,13 +50,15 @@ object AttributeKey
private[this] def make[T](name: String, description0: Option[String], extend0: Seq[AttributeKey[_]], rank0: Int)(implicit mf: Manifest[T]): AttributeKey[T] = new SharedAttributeKey[T] {
def manifest = mf
def label = name
def rawLabel = name
val label = Util.hyphenToCamel(name)
def description = description0
def extend = extend0
def rank = rank0
}
private[sbt] def local[T](implicit mf: Manifest[T]): AttributeKey[T] = new AttributeKey[T] {
def manifest = mf
def rawLabel = LocalLabel
def label = LocalLabel
def description = None
def extend = Nil

View File

@ -26,8 +26,14 @@ object Util
def pairID[A,B] = (a: A, b: B) => (a,b)
private[this] lazy val Hypen = """-(\p{javaLowerCase})""".r
def hypenToCamel(s: String): String =
Hypen.replaceAllIn(s, _.group(1).toUpperCase)
def hasHyphen(s: String): Boolean = s.indexOf('-') >= 0
@deprecated("Use the properly spelled version: hyphenToCamel", "0.13.0")
def hypenToCamel(s: String): String = hyphenToCamel(s)
def hyphenToCamel(s: String): String =
if(hasHyphen(s))
Hypen.replaceAllIn(s, _.group(1).toUpperCase)
else
s
private[this] lazy val Camel = """(\p{javaLowerCase})(\p{javaUpperCase})""".r
def camelToHypen(s: String): String =