Support usageLineLength in CommandRunner (#115)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4707541..e0cefde 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,7 @@
+## 1.5.2
+
+* Added support for `usageLineLength` in `CommandRunner`
+
## 1.5.1
* Added more comprehensive word wrapping when `usageLineLength` is set.
diff --git a/lib/command_runner.dart b/lib/command_runner.dart
index 5ca4084..4962a17 100644
--- a/lib/command_runner.dart
+++ b/lib/command_runner.dart
@@ -75,9 +75,10 @@
/// available via [Command.globalResults]. Commands should be registered with
/// [addCommand] rather than directly on the parser.
ArgParser get argParser => _argParser;
- final _argParser = ArgParser();
+ final ArgParser _argParser;
- CommandRunner(this.executableName, this.description) {
+ CommandRunner(this.executableName, this.description, {int usageLineLength})
+ : _argParser = ArgParser(usageLineLength: usageLineLength) {
argParser.addFlag('help',
abbr: 'h', negatable: false, help: 'Print this usage information.');
addCommand(HelpCommand<T>());
diff --git a/test/command_runner_test.dart b/test/command_runner_test.dart
index e9a3cfb..553271a 100644
--- a/test/command_runner_test.dart
+++ b/test/command_runner_test.dart
@@ -135,6 +135,25 @@
Run "test help <command>" for more information about a command."""));
});
+
+ test("respects usageLineLength", () {
+ runner = CommandRunner("name", "desc", usageLineLength: 35);
+ expect(runner.usage, equals("""
+desc
+
+Usage: name <command> [arguments]
+
+Global options:
+-h, --help Print this usage
+ information.
+
+Available commands:
+ help Display help information
+ for name.
+
+Run "name help <command>" for more
+information about a command."""));
+ });
});
test("usageException splits up the message and usage", () {