diff --git a/main-command/src/main/scala/sbt/Command.scala b/main-command/src/main/scala/sbt/Command.scala index f90aedc8e..05798ff55 100644 --- a/main-command/src/main/scala/sbt/Command.scala +++ b/main-command/src/main/scala/sbt/Command.scala @@ -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 { diff --git a/sbt/src/sbt-test/actions/command-name/build.sbt b/sbt/src/sbt-test/actions/command-name/build.sbt new file mode 100644 index 000000000..1a04a2dcc --- /dev/null +++ b/sbt/src/sbt-test/actions/command-name/build.sbt @@ -0,0 +1,5 @@ +val command = Command.command("noop") { s => s } + +TaskKey[Unit]("check") := { + assert(command.commandName == Some("noop"), """command.commandName should be "noop"""") +} diff --git a/sbt/src/sbt-test/actions/command-name/test b/sbt/src/sbt-test/actions/command-name/test new file mode 100644 index 000000000..a5912a391 --- /dev/null +++ b/sbt/src/sbt-test/actions/command-name/test @@ -0,0 +1 @@ +> check \ No newline at end of file