45 lines
1.1 KiB
Scala
45 lines
1.1 KiB
Scala
package gs
|
|
|
|
import sbt._
|
|
import scala.util.Try
|
|
|
|
/** Helper for managing all SBT command line properties (`-Dproperty=value`).
|
|
*/
|
|
object PluginProperties {
|
|
|
|
/** Helper to extract the value from `-Dproperty=value`.
|
|
*
|
|
* @param name
|
|
* The property name.
|
|
* @param conv
|
|
* The conversion function to the output type.
|
|
* @return
|
|
* The converted value, or `None` if no value exists.
|
|
*/
|
|
def getProperty[A](
|
|
name: String,
|
|
conv: String => A
|
|
): Option[A] =
|
|
Option(System.getProperty(name)).map(conv)
|
|
|
|
/** Use one of the following to calculate an incremented release version:
|
|
*
|
|
* - `sbt -Drelease=true`
|
|
* - `sbt -Drelease=false`
|
|
*/
|
|
val ReleaseProperty: String = "release"
|
|
|
|
/** The value of `-Drelease=<true|false>`, parsed and validated.
|
|
*
|
|
* If no value is specified, `false` is assumed.
|
|
*
|
|
* @return
|
|
* The `release` setting passed as input to SBT.
|
|
*/
|
|
def isRelease(): Boolean =
|
|
getProperty(
|
|
ReleaseProperty,
|
|
raw => Try(raw.toBoolean).getOrElse(false)
|
|
).getOrElse(false)
|
|
|
|
}
|