From 619b97d2152ce05fa0fc0e2a5d6f91fd4babe2f0 Mon Sep 17 00:00:00 2001 From: Mark Harrah Date: Fri, 16 Dec 2011 08:21:54 -0500 Subject: [PATCH] apply * : command to apply State transformations defined by module names --- main/Command.scala | 9 +++------ main/CommandSupport.scala | 4 ++++ main/Main.scala | 7 ++++++- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/main/Command.scala b/main/Command.scala index cb45a6590..40245b180 100644 --- a/main/Command.scala +++ b/main/Command.scala @@ -178,11 +178,8 @@ object Help def briefOnly(help: Seq[(String, String)]): Help = apply(help, Map.empty[String,String]) def detailOnly(help: Seq[(String, String)]): Help = apply(Nil, help.toMap) } -trait CommandDefinitions +trait CommandDefinitions extends (State => State) { - def commands: Seq[Command] + def commands: Seq[Command] = ReflectUtilities.allVals[Command](this).values.toSeq + def apply(s: State): State = s ++ commands } -trait ReflectedCommands extends CommandDefinitions -{ - def commands = ReflectUtilities.allVals[Command](this).values.toSeq -} \ No newline at end of file diff --git a/main/CommandSupport.scala b/main/CommandSupport.scala index 3951885a9..b65ae5f43 100644 --- a/main/CommandSupport.scala +++ b/main/CommandSupport.scala @@ -197,6 +197,10 @@ ReadCommand + ReadFiles + """ You probably need to escape this command if entering it at your shell.""" + def ApplyCommand = "apply" + def ApplyBrief = (ApplyCommand + " *", ApplyDetailed) + def ApplyDetailed = "Transforms the current State by calling .apply(currentState) for each listed." + def DefaultsCommand = "add-default-commands" def DefaultsBrief = (DefaultsCommand, DefaultsDetailed) def DefaultsDetailed = "Registers default built-in commands" diff --git a/main/Main.scala b/main/Main.scala index 787dbdd83..941bc90db 100644 --- a/main/Main.scala +++ b/main/Main.scala @@ -135,7 +135,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, 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, boot, nop, sessionCommand, act) + projects, project, setOnFailure, clearOnFailure, ifLast, multi, shell, set, tasks, inspect, eval, alias, append, last, lastGrep, boot, nop, sessionCommand, call, act) def DefaultBootCommands: Seq[String] = LoadProject :: (IfLast + " " + Shell) :: Nil def boot = Command.make(BootCommand)(bootParser) @@ -302,6 +302,11 @@ object BuiltinCommands def defaults = Command.command(DefaultsCommand) { s => s ++ DefaultCommands } + def call = Command(ApplyCommand, ApplyBrief, ApplyDetailed)(_ => spaceDelimited("")) { (state,args) => + val loader = getClass.getClassLoader + val loaded = args.map(arg => ModuleUtilities.getObject(arg, loader)) + (state /: loaded) { case (s, obj: (State => State)) => obj(s) } + } def initialize = Command.command(InitCommand) { s => /*"load-commands -base ~/.sbt/commands" :: */readLines( readable( sbtRCs(s) ) ) ::: s