apply <module>* : command to apply State transformations defined by module names

This commit is contained in:
Mark Harrah 2011-12-16 08:21:54 -05:00
parent 5d398bc4a1
commit 619b97d215
3 changed files with 13 additions and 7 deletions

View File

@ -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
}

View File

@ -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 + " <module-name>*", ApplyDetailed)
def ApplyDetailed = "Transforms the current State by calling <module-name>.apply(currentState) for each listed."
def DefaultsCommand = "add-default-commands"
def DefaultsBrief = (DefaultsCommand, DefaultsDetailed)
def DefaultsDetailed = "Registers default built-in commands"

View File

@ -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("<class name>")) { (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