Don't truncate multi-line command descriptions.
Closes #42
R=rnystrom@google.com
Review URL: https://codereview.chromium.org//1603063004 .
diff --git a/.gitignore b/.gitignore
index 388eff0..7dbf035 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,6 +3,7 @@
.pub/
build/
packages
+.packages
# Or the files created by dart2js.
*.dart.js
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 123c564..250b601 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,7 @@
+## 0.13.2+1
+
+* Print all lines of multi-line command descriptions.
+
## 0.13.2
* Allow option values that look like options. This more closely matches the
diff --git a/lib/command_runner.dart b/lib/command_runner.dart
index 10b87ce..df1dbf8 100644
--- a/lib/command_runner.dart
+++ b/lib/command_runner.dart
@@ -371,9 +371,15 @@
var buffer =
new StringBuffer('Available ${isSubcommand ? "sub" : ""}commands:');
for (var name in names) {
+ var lines = commands[name].description.split("\n");
buffer.writeln();
- buffer.write(' ${padRight(name, length)} '
- '${commands[name].description.split("\n").first}');
+ buffer.write(' ${padRight(name, length)} ${lines.first}');
+
+ for (var line in lines.skip(1)) {
+ buffer.writeln();
+ buffer.write(' ' * (length + 5));
+ buffer.write(line);
+ }
}
return buffer.toString();
diff --git a/pubspec.yaml b/pubspec.yaml
index a4eb70c..702f008 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,5 +1,5 @@
name: args
-version: 0.13.3-dev
+version: 0.13.3+1
author: "Dart Team <misc@dartlang.org>"
homepage: https://github.com/dart-lang/args
description: >
diff --git a/test/command_runner_test.dart b/test/command_runner_test.dart
index f3a74a0..bccc7b3 100644
--- a/test/command_runner_test.dart
+++ b/test/command_runner_test.dart
@@ -54,6 +54,25 @@
Run "test help <command>" for more information about a command."""));
});
+ test("supports newlines in command descriptions", () {
+ runner.addCommand(new MultilineCommand());
+
+ expect(runner.usage, equals("""
+A test command runner.
+
+Usage: test <command> [arguments]
+
+Global options:
+-h, --help Print this usage information.
+
+Available commands:
+ help Display help information for test.
+ multiline Multi
+ line.
+
+Run "test help <command>" for more information about a command."""));
+ });
+
test("contains custom options", () {
runner.argParser.addFlag("foo", help: "Do something.");
diff --git a/test/utils.dart b/test/utils.dart
index b6c6c71..3ef6887 100644
--- a/test/utils.dart
+++ b/test/utils.dart
@@ -27,6 +27,18 @@
}
}
+class MultilineCommand extends Command {
+ var hasRun = false;
+
+ final name = "multiline";
+ final description = "Multi\nline.";
+ final takesArguments = false;
+
+ void run() {
+ hasRun = true;
+ }
+}
+
class HiddenCommand extends Command {
var hasRun = false;