Skip to content

Commit f6b75d4

Browse files
committed
Fix extra newlines after separators
Fixes #917 Reset the `_currentColumn` after writing separator lines and marking the need for a newline. Previously if a flag was written with no help text the current column would remain at the position where help text would otherwise be written. On the next write the target `column` would be lower so an extra line is added to wrap back to the intended column.
1 parent 455d544 commit f6b75d4

4 files changed

Lines changed: 33 additions & 2 deletions

File tree

pkgs/args/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## 2.8.0
1+
## 2.8.0-wip
22

33
* Allow designating a top-level command or a subcommand as a default one by
44
passing `isDefault: true` to `addCommand` or `addSubcommand`.
@@ -8,6 +8,7 @@
88
(Fixes #103).
99
* Remove sorting of the subcommands in usage output. Ordering will depend on the
1010
order that `addSubCommand` is called.
11+
* Remove extra newlines following separators when using flags without help text.
1112

1213
## 2.7.0
1314

pkgs/args/lib/src/usage.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class _Usage {
8181
if (_buffer.isNotEmpty) _buffer.write('\n\n');
8282
_buffer.write(separator);
8383
_newlinesNeeded = 1;
84+
_currentColumn = 0;
8485
}
8586

8687
void _writeOption(Option option) {

pkgs/args/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: args
2-
version: 2.8.0
2+
version: 2.8.0-wip
33
description: >-
44
Library for defining parsers for parsing raw command-line arguments into a set
55
of options and values using GNU and POSIX style options.

pkgs/args/test/usage_test.dart

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,35 @@ void main() {
455455
--[no-]wombat Third
456456
''');
457457
});
458+
test('consistently attaches separator headers to options', () {
459+
var parser = ArgParser()
460+
..addSeparator('Group 1')
461+
..addFlag('flag-1')
462+
..addSeparator('Group 2 (follows no options with help)')
463+
..addFlag('flag-2', help: 'something')
464+
..addFlag('flag-3')
465+
..addSeparator('Group 3 (follows non-trailing option with help)')
466+
..addFlag('flag-4')
467+
..addFlag('flag-5', help: 'something')
468+
..addSeparator('Group 4 (follows trailing option with help)')
469+
..addFlag('flag-6');
470+
471+
validateUsage(parser, '''
472+
Group 1
473+
--[no-]flag-1
474+
475+
Group 2 (follows no options with help)
476+
--[no-]flag-2 something
477+
--[no-]flag-3
478+
479+
Group 3 (follows non-trailing option with help)
480+
--[no-]flag-4
481+
--[no-]flag-5 something
482+
483+
Group 4 (follows trailing option with help)
484+
--[no-]flag-6
485+
''');
486+
});
458487

459488
test("doesn't add extra newlines after a multiline option", () {
460489
var parser = ArgParser();

0 commit comments

Comments
 (0)