Add commandName as an extension method in Command
This commit is contained in:
Miklos Martin 2017-10-26 16:31:40 +02:00
parent 12c2e9b8e7
commit 8dacb72f9d
3 changed files with 13 additions and 0 deletions

View File

@ -187,6 +187,13 @@ object Command {
def spacedC(name: String, c: Parser[Char]): Parser[String] =
((c & opOrIDSpaced(name)) ~ c.+) map { case (f, rem) => (f +: rem).mkString }
implicit class CommandWithName(cmd: Command) {
def commandName: Option[String] = cmd match {
case sc: SimpleCommand => Some(sc.name)
case _ => None
}
}
}
trait Help {

View File

@ -0,0 +1,5 @@
val command = Command.command("noop") { s => s }
TaskKey[Unit]("check") := {
assert(command.commandName == Some("noop"), """command.commandName should be "noop"""")
}

View File

@ -0,0 +1 @@
> check