add 'about' command with sbt versions and Scala versions

This commit is contained in:
Mark Harrah 2011-07-24 17:36:42 -04:00
parent 109326d34b
commit 2d4d27e529
3 changed files with 29 additions and 6 deletions

View File

@ -33,6 +33,7 @@ object CommandSupport
/** The prefix used to identify a request to execute the remaining input on source changes.*/
val ContinuousExecutePrefix = "~"
val HelpCommand = "help"
val AboutCommand = "about"
val TasksCommand = "tasks"
val ProjectCommand = "project"
val ProjectsCommand = "projects"
@ -121,6 +122,9 @@ Tasks produce values. Use the 'show' command to run the task and print the resu
def helpBrief = (HelpCommand + " command*", "Displays this help message or prints detailed help on requested commands.")
def helpDetailed = "If an argument is provided, this prints detailed help for that command.\nOtherwise, this prints a help summary."
def aboutBrief = "Displays basic information about sbt and the build."
def aboutDetailed = aboutBrief
def projectBrief = (ProjectCommand + " [project]", "Displays the current project or changes to the provided `project`.")
def projectDetailed =
ProjectCommand +

View File

@ -79,7 +79,7 @@ object BuiltinCommands
def ConsoleCommands: Seq[Command] = Seq(ignore, exit, IvyConsole.command, act, nop)
def ScriptCommands: Seq[Command] = Seq(ignore, exit, Script.command, act, nop)
def DefaultCommands: Seq[Command] = Seq(ignore, help, reboot, read, history, continuous, exit, loadProject, loadProjectImpl, loadFailed, Cross.crossBuild, Cross.switchVersion,
def DefaultCommands: Seq[Command] = Seq(ignore, help, about, reboot, read, history, continuous, exit, loadProject, loadProjectImpl, loadFailed, Cross.crossBuild, Cross.switchVersion,
projects, project, setOnFailure, clearOnFailure, ifLast, multi, shell, set, tasks, inspect, eval, alias, append, last, lastGrep, nop, sessionCommand, act)
def DefaultBootCommands: Seq[String] = LoadProject :: (IfLast + " " + Shell) :: Nil
@ -90,6 +90,7 @@ object BuiltinCommands
h.detail match { case (commands, value) => if( selected exists commands ) Some(value) else None }
def help = Command.make(HelpCommand, helpBrief, helpDetailed)(helpParser)
def about = Command.command(AboutCommand, aboutBrief, aboutDetailed) { s => logger(s).info(aboutString(s)); s }
def helpParser(s: State) =
{
@ -109,6 +110,26 @@ object BuiltinCommands
System.out.println(message)
s
}
def sbtVersion(s: State): String = s.configuration.provider.id.version
def scalaVersion(s: State): String = s.configuration.provider.scalaProvider.version
def aboutString(s: State): String =
{
"This is sbt " + sbtVersion(s) + "\n" +
aboutProject(s) +
"sbt, sbt plugins, and build definitions are using Scala " + scalaVersion(s)
}
def aboutProject(s: State): String =
if(Project.isProjectLoaded(s))
{
val e = Project.extract(s)
val current = "The current project is " + Project.display(e.currentRef) + "\n"
val built = e.getOpt(Keys.scalaVersion) match {
case Some(sv) => "The current project is built against Scala " + sv + "\n"
case None => ""
}
current + built
}
else "No project is currently loaded.\n"
def tasks = Command.command(TasksCommand, tasksBrief, tasksDetailed) { s =>
System.out.println(tasksPreamble)

View File

@ -68,11 +68,9 @@ final case class Extracted(structure: BuildStructure, session: SessionSettings,
lazy val currentProject = currentUnit defined currentRef.project
lazy val currentLoader: ClassLoader = currentUnit.loader
def get[T](key: ScopedTask[T]): Task[T] = get(key.task)
def get[T](key: ScopedSetting[T]): T =
{
val scope = if(key.scope.project == This) key.scope.copy(project = Select(currentRef)) else key.scope
getOrError(scope, key.key)
}
def get[T](key: ScopedSetting[T]): T = getOrError(inCurrent(key), key.key)
def getOpt[T](key: ScopedSetting[T]): Option[T] = structure.data.get(inCurrent(key), key.key)
private[this] def inCurrent[T](key: ScopedSetting[T]): Scope = if(key.scope.project == This) key.scope.copy(project = Select(currentRef)) else key.scope
def evalTask[T](key: ScopedTask[T], state: State): T =
{
import EvaluateTask._