diff --git a/main/Command.scala b/main/Command.scala index 4d31db162..7fa07de28 100644 --- a/main/Command.scala +++ b/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 } \ No newline at end of file diff --git a/main/Main.scala b/main/Main.scala index c9f47327e..0dcc5c2a2 100644 --- a/main/Main.scala +++ b/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() {