From 2d4d27e529a777d79fdd8b7b427d392f028ae447 Mon Sep 17 00:00:00 2001 From: Mark Harrah Date: Sun, 24 Jul 2011 17:36:42 -0400 Subject: [PATCH] add 'about' command with sbt versions and Scala versions --- main/CommandSupport.scala | 4 ++++ main/Main.scala | 23 ++++++++++++++++++++++- main/Project.scala | 8 +++----- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/main/CommandSupport.scala b/main/CommandSupport.scala index c2c152848..1be8a743e 100644 --- a/main/CommandSupport.scala +++ b/main/CommandSupport.scala @@ -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 + diff --git a/main/Main.scala b/main/Main.scala index 58ade89e1..7c51ed2bd 100644 --- a/main/Main.scala +++ b/main/Main.scala @@ -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) diff --git a/main/Project.scala b/main/Project.scala index 000878842..dddb2ad5c 100644 --- a/main/Project.scala +++ b/main/Project.scala @@ -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._