Skip to content

Commit

Permalink
Don't truncate multi-line command descriptions.
Browse files Browse the repository at this point in the history
Closes #42

R=rnystrom@google.com

Review URL: https://codereview.chromium.org//1603063004 .
  • Loading branch information
nex3 committed Jan 20, 2016
1 parent 7097a89 commit ff4dd9a
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -3,6 +3,7 @@
.pub/
build/
packages
.packages

# Or the files created by dart2js.
*.dart.js
Expand Down
4 changes: 4 additions & 0 deletions 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
Expand Down
10 changes: 8 additions & 2 deletions lib/command_runner.dart
Expand Up @@ -371,9 +371,15 @@ String _getCommandUsage(Map<String, Command> commands,
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();
Expand Down
2 changes: 1 addition & 1 deletion 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: >
Expand Down
19 changes: 19 additions & 0 deletions test/command_runner_test.dart
Expand Up @@ -51,6 +51,25 @@ Available commands:
foo Set a value.
help Display help information for test.
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."""));
});

Expand Down
12 changes: 12 additions & 0 deletions test/utils.dart
Expand Up @@ -27,6 +27,18 @@ class FooCommand extends Command {
}
}

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;

Expand Down

0 comments on commit ff4dd9a

Please sign in to comment.