Add commandName as an extension method in Command
This commit is contained in:
Miklos Martin
2017-11-03 06:39:53 +01:00
parent 12c2e9b8e7
commit 8dacb72f9d
3 changed files with 13 additions and 0 deletions
@@ -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 {
@@ -0,0 +1,5 @@
val command = Command.command("noop") { s => s }
TaskKey[Unit]("check") := {
assert(command.commandName == Some("noop"), """command.commandName should be "noop"""")
}
@@ -0,0 +1 @@
> check