native type should be T => Option[O] not PartialFunction[T, O]

This commit is contained in:
Mark Harrah 2010-07-19 12:31:22 -04:00
parent d7b66458f2
commit 1169493115
2 changed files with 13 additions and 6 deletions

View File

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

View File

@ -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")