Review changes.
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2a335e7..1fbb54c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,7 @@
+## 1.5.1-dev
+
+* Added more comprehensive word wrapping when `usageLineLength` is set.
+
## 1.5.0
* Add `usageLineLength` to control word wrapping usage text.
diff --git a/lib/command_runner.dart b/lib/command_runner.dart
index 62f7fe7..fa2babd 100644
--- a/lib/command_runner.dart
+++ b/lib/command_runner.dart
@@ -49,21 +49,20 @@
/// Returns [usage] with [description] removed from the beginning.
String get _usageWithoutDescription {
- const usagePrefix = "Usage:";
- var usage = '''
-$usagePrefix ${_wrap(invocation, hangingIndent: usagePrefix.length)}
-
-${_wrap('Global options:')}
-${argParser.usage}
-
-${_getCommandUsage(_commands, lineLength: argParser.usageLineLength)}
-
-${_wrap('Run "$executableName help <command>" for more information about a command.')}''';
-
+ var usagePrefix = "Usage:";
+ var buffer = new StringBuffer();
+ buffer.writeln(
+ '$usagePrefix ${_wrap(invocation, hangingIndent: usagePrefix.length)}\n');
+ buffer.writeln(_wrap('Global options:'));
+ buffer.writeln('${argParser.usage}\n');
+ buffer.writeln(
+ '${_getCommandUsage(_commands, lineLength: argParser.usageLineLength)}\n');
+ buffer.write(_wrap(
+ 'Run "$executableName help <command>" for more information about a command.'));
if (usageFooter != null) {
- usage += "\n${_wrap(usageFooter)}";
+ buffer.write('\n${_wrap(usageFooter)}');
}
- return usage;
+ return buffer.toString();
}
/// An unmodifiable view of all top-level commands defined for this runner.
@@ -298,8 +297,8 @@
/// Returns [usage] with [description] removed from the beginning.
String get _usageWithoutDescription {
- final length = argParser.usageLineLength;
- const usagePrefix = "Usage: ";
+ var length = argParser.usageLineLength;
+ var usagePrefix = "Usage: ";
var buffer = new StringBuffer()
..writeln(
usagePrefix + _wrap(invocation, hangingIndent: usagePrefix.length))
@@ -419,8 +418,8 @@
var buffer =
new StringBuffer('Available ${isSubcommand ? "sub" : ""}commands:');
+ var columnStart = length + 5;
for (var name in names) {
- var columnStart = length + 5;
var lines = wrapTextAsLines(commands[name].summary,
start: columnStart, length: lineLength);
buffer.writeln();
diff --git a/lib/src/utils.dart b/lib/src/utils.dart
index 9c3972f..da705b1 100644
--- a/lib/src/utils.dart
+++ b/lib/src/utils.dart
@@ -13,9 +13,9 @@
/// under the limit, then it splits in the middle of a word.
///
/// Preserves indentation (leading whitespace) for each line (delimited by '\n')
-/// in the input, and will indent wrapped lines the same amount.
+/// in the input, and indents wrapped lines the same amount.
///
-/// If [hangingIndent] is supplied, then that many spaces will be added to each
+/// If [hangingIndent] is supplied, then that many spaces are added to each
/// line, except for the first line. This is useful for flowing text with a
/// heading prefix (e.g. "Usage: "):
///
@@ -46,34 +46,26 @@
// When we have a hanging indent, we want to wrap the first line at one
// width, and the rest at another (offset by hangingIndent), so we wrap
// them twice and recombine.
- final firstLineWrap = wrapTextAsLines(
- trimmedText,
- length: length - leadingWhitespace.length,
- );
- notIndented = <String>[firstLineWrap.removeAt(0)];
+ var firstLineWrap = wrapTextAsLines(trimmedText,
+ length: length - leadingWhitespace.length);
+ notIndented = [firstLineWrap.removeAt(0)];
trimmedText = trimmedText.substring(notIndented[0].length).trimLeft();
if (firstLineWrap.isNotEmpty) {
- notIndented.addAll(wrapTextAsLines(
- trimmedText,
- length: length - leadingWhitespace.length - hangingIndent,
- ));
+ notIndented.addAll(wrapTextAsLines(trimmedText,
+ length: length - leadingWhitespace.length - hangingIndent));
}
} else {
- notIndented = wrapTextAsLines(
- trimmedText,
- length: length - leadingWhitespace.length,
- );
+ notIndented = wrapTextAsLines(trimmedText,
+ length: length - leadingWhitespace.length);
}
String hangingIndentString;
- result.addAll(notIndented.map<String>(
- (String line) {
- // Don't return any lines with just whitespace on them.
- if (line.isEmpty) return "";
- var result = "${hangingIndentString ?? ""}$leadingWhitespace$line";
- hangingIndentString ??= " " * hangingIndent;
- return result;
- },
- ));
+ result.addAll(notIndented.map<String>((String line) {
+ // Don't return any lines with just whitespace on them.
+ if (line.isEmpty) return '';
+ var result = '${hangingIndentString ?? ''}$leadingWhitespace$line';
+ hangingIndentString ??= ' ' * hangingIndent;
+ return result;
+ }));
}
return result.join('\n');
}
@@ -96,7 +88,7 @@
///
/// Based on: https://en.wikipedia.org/wiki/Whitespace_character#Unicode
bool isWhitespace(String text, int index) {
- final rune = text.codeUnitAt(index);
+ var rune = text.codeUnitAt(index);
return rune >= 0x0009 && rune <= 0x000D ||
rune == 0x0020 ||
rune == 0x0085 ||
@@ -113,8 +105,8 @@
if (length == null) return text.split('\n');
- final result = <String>[];
- final effectiveLength = math.max(length - start, 10);
+ var result = <String>[];
+ var effectiveLength = math.max(length - start, 10);
for (var line in text.split('\n')) {
line = line.trim();
if (line.length <= effectiveLength) {
diff --git a/pubspec.yaml b/pubspec.yaml
index 3f52f94..f68421b 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,5 +1,5 @@
name: args
-version: 1.5.0
+version: 1.5.1-dev
author: "Dart Team <misc@dartlang.org>"
homepage: https://github.com/dart-lang/args
description: >