From 97ed5822c742a9b7f3a624e727f3033a4f34f7b0 Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Tue, 5 May 2015 09:11:28 +0100 Subject: [PATCH] Implement SimpleCommand.toString. Fixes #1998. --- main/command/src/main/scala/sbt/Command.scala | 1 + notes/0.13.9/command-to-string.markdown | 12 ++++++++++++ sbt/src/sbt-test/actions/command-to-string/build.sbt | 6 ++++++ sbt/src/sbt-test/actions/command-to-string/test | 1 + 4 files changed, 20 insertions(+) create mode 100644 notes/0.13.9/command-to-string.markdown create mode 100644 sbt/src/sbt-test/actions/command-to-string/build.sbt create mode 100644 sbt/src/sbt-test/actions/command-to-string/test diff --git a/main/command/src/main/scala/sbt/Command.scala b/main/command/src/main/scala/sbt/Command.scala index 7c98bb6e8..2da40fcc4 100644 --- a/main/command/src/main/scala/sbt/Command.scala +++ b/main/command/src/main/scala/sbt/Command.scala @@ -17,6 +17,7 @@ private[sbt] final class SimpleCommand(val name: String, private[sbt] val help0: assert(Command validID name, "'" + name + "' is not a valid command name.") def tag[T](key: AttributeKey[T], value: T): SimpleCommand = new SimpleCommand(name, help0, parser, tags.put(key, value)) def help = const(help0) + override def toString = s"SimpleCommand($name)" } private[sbt] final class ArbitraryCommand(val parser: State => Parser[() => State], val help: State => Help, val tags: AttributeMap) extends Command { def tag[T](key: AttributeKey[T], value: T): ArbitraryCommand = new ArbitraryCommand(parser, help, tags.put(key, value)) diff --git a/notes/0.13.9/command-to-string.markdown b/notes/0.13.9/command-to-string.markdown new file mode 100644 index 000000000..41066072a --- /dev/null +++ b/notes/0.13.9/command-to-string.markdown @@ -0,0 +1,12 @@ + + [@dwijnand]: http://github.com/dwijnand + [1998]: https://github.com/sbt/sbt/issues/1998 + [2000]: https://github.com/sbt/sbt/pull/2000 + +### Fixes with compatibility implications + +### Improvements + +- Add a nicer toString to SimpleCommand to make it more human-friendly. [#1998][1998]/[#2000][2000] by [@dwijnand][@dwijnand] + +### Bug fixes diff --git a/sbt/src/sbt-test/actions/command-to-string/build.sbt b/sbt/src/sbt-test/actions/command-to-string/build.sbt new file mode 100644 index 000000000..00aeb8a65 --- /dev/null +++ b/sbt/src/sbt-test/actions/command-to-string/build.sbt @@ -0,0 +1,6 @@ +commands += Command.command("noop") { s => s } + +TaskKey[Unit]("check") := { + assert(commands.value.toString() == "List(SimpleCommand(noop))", + s"""commands should display "List(SimpleCommand(noop))" but is ${commands.value}""") +} diff --git a/sbt/src/sbt-test/actions/command-to-string/test b/sbt/src/sbt-test/actions/command-to-string/test new file mode 100644 index 000000000..15675b169 --- /dev/null +++ b/sbt/src/sbt-test/actions/command-to-string/test @@ -0,0 +1 @@ +> check