mirror of https://github.com/sbt/sbt.git
native type should be T => Option[O] not PartialFunction[T, O]
This commit is contained in:
parent
d7b66458f2
commit
1169493115
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
Loading…
Reference in New Issue