Browse files

change from user commands extending Command directly to providing Com…

…mandDefinitions instance that creates commands
  • Loading branch information...
1 parent 32150e7 commit 39839f2c1633c18f625184e519516c8d654f0db6 @harrah committed Aug 10, 2010
Showing with 15 additions and 5 deletions.
  1. +9 −2 main/Command.scala
  2. +6 −3 main/Main.scala
View
11 main/Command.scala
@@ -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
9 main/Main.scala
@@ -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() {

0 comments on commit 39839f2

Please sign in to comment.