change from user commands extending Command directly to providing CommandDefinitions instance that creates commands

This commit is contained in:
Mark Harrah 2010-08-10 08:44:34 -04:00
parent 32150e7097
commit 39839f2c16
2 changed files with 15 additions and 5 deletions

View File

@ -6,11 +6,10 @@ package sbt
import Execute.NodeView
import Completions.noCompletions
sealed trait Command
trait Command
{
def applies: State => Option[Apply]
}
trait UserCommand extends Command
trait Apply
{
def help: Seq[Help]
@ -108,4 +107,12 @@ object Input
object Next extends Enumeration {
val Reload, Fail, Done, Continue = Value
}
trait CommandDefinitions
{
def commands: Seq[Command]
}
trait ReflectedCommands extends CommandDefinitions
{
def commands = ReflectUtilities.allVals[Command](this).values.toSeq
}

View File

@ -244,12 +244,15 @@ object Commands
}
def buildCommands(arguments: String, configuration: xsbti.AppConfiguration): Either[Throwable, Seq[Any]] =
loadCommand(arguments, configuration, true, classOf[UserCommand].getName)
loadCommand(arguments, configuration, true, classOf[CommandDefinitions].getName)
def applyCommands(s: State, commands: Either[Throwable, Seq[Any]]): State =
commands match {
case Right(newCommands) =>
val asCommands = newCommands map { case c: Command => c; case x => error("Not a Command: " + x.asInstanceOf[AnyRef].getClass) }
val asCommands = newCommands flatMap {
case c: CommandDefinitions => c.commands
case x => error("Not an instance of CommandDefinitions: " + x.asInstanceOf[AnyRef].getClass)
}
s.copy()(processors = asCommands ++ s.processors)
case Left(e) => e.printStackTrace; System.err.println(e.toString); s.fail // TODO: log instead of print
}
@ -323,7 +326,7 @@ object Commands
def aliasStrings(s: State) = aliases(s).map(a => a.name + " = " + a.value)
def aliases(s: State) = s.processors collect { case a: Alias => a }
final class Alias(val name: String, val value: String) extends UserCommand {
final class Alias(val name: String, val value: String) extends Command {
assert(name.length > 0)
assert(value.length > 0)
def applies = s => Some(Apply() {