diff --git a/main/Command.scala b/main/Command.scala index c77d10a76..ba7b84fd2 100644 --- a/main/Command.scala +++ b/main/Command.scala @@ -3,27 +3,34 @@ */ package sbt +import Execute.NodeView + sealed trait Command { - def applies: PartialFunction[State, Apply] + def applies: State => Option[Apply] } trait Apply { def help: Seq[(String,String)] - def run: PartialFunction[Input, State] + def run: Input => Option[State] } object Command { - def apply(f: PartialFunction[State, Apply]): Command = + def direct(f: State => Option[Apply]): Command = new Command { def applies = f } + def apply(f: PartialFunction[State, Apply]): Command = + direct(f.lift) def simple(name: String, help: (String, String)*)(f: State => State): Command = apply { case s => Apply(help) { case in if in.line == name => f(s) }} } object Apply { - def apply(h: Seq[(String,String)])(r: PartialFunction[Input, State]): Apply = + def direct(h: Seq[(String,String)])(r: Input => Option[State]): Apply = new Apply { def help = h; def run = r } + + def apply(h: Seq[(String,String)])(r: PartialFunction[Input, State]): Apply = + direct(h)(r.lift) } trait Logged diff --git a/main/Main.scala b/main/Main.scala index fe0a826d5..580d4e470 100644 --- a/main/Main.scala +++ b/main/Main.scala @@ -36,7 +36,7 @@ class xMain extends xsbti.AppMain def process(command: String, state: State): State = { val in = Input(command) - Commands.applicable(state).flatMap( _.run.lift(in) ).headOption.getOrElse { + Commands.applicable(state).flatMap( _.run(in) ).headOption.getOrElse { System.err.println("Unknown command '" + command + "'") state.fail } @@ -48,7 +48,7 @@ class xMain extends xsbti.AppMain object Commands { def applicable(state: State): Stream[Apply] = - state.processors.toStream.flatMap(_.applies.lift(state) ) + state.processors.toStream.flatMap(_.applies(state) ) def help = Command.simple("help", ("help", "Displays this help message.")) { s => val message = applicable(s).flatMap(_.help).map { case (a,b) => a + " : " + b }.mkString("\n")