Skip to content

Commit f477bdd

Browse files
committed
Remove sorting of allowedHelp maps
Closes #845 It is idiomatic to treat the key order of a Dart map as meaningful given that map literals and default Map type preserve key insertion order. It is more useful to allow the caller to decide this order than to mandate an alpha sorting by key. Callers which need this order can construct the map appropriately, and callers which prefer a different order now have the capability. Releasing as a non-breaking change since specific usage output is considered an implementation detail. This is expected to impact some CI statuf for packages with tests hardcoding a strict dependency on the output. No additional tests are necessary since updating the order in existing tests demonstrates the same behavior as adding a non-sorting specific test.
1 parent a59cbea commit f477bdd

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

pkgs/args/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## 2.6.1-wip
22

3+
* Remove sorting of the `allowedHelp` argument in usage output. Ordering will
4+
depend on key order for the passed `Map`.
35
* Fix the repository URL in `pubspec.yaml`.
46
* Added option `hideNegatedUsage` to `ArgParser.flag()` allowing a flag to be
57
`negatable` without showing it in the usage text.

pkgs/args/lib/src/usage.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,7 @@ class _Usage {
9090
if (option.help != null) _write(2, option.help!);
9191

9292
if (option.allowedHelp != null) {
93-
var allowedNames = option.allowedHelp!.keys.toList();
94-
allowedNames.sort();
93+
var allowedNames = [...option.allowedHelp!.keys];
9594
_newline();
9695
for (var name in allowedNames) {
9796
_write(1, _allowedTitle(option, name));

pkgs/args/test/usage_test.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,10 @@ void main() {
216216
validateUsage(parser, '''
217217
--suit Like in cards
218218
219+
[spades] Swords of a soldier
219220
[clubs] Weapons of war
220221
[diamonds] Money for this art
221222
[hearts] The shape of my heart
222-
[spades] Swords of a soldier
223223
''');
224224
});
225225

@@ -244,10 +244,10 @@ void main() {
244244
validateUsage(parser, '''
245245
--suit Like in cards
246246
247+
[spades] Swords of a soldier
247248
[clubs] (default) Weapons of war
248249
[diamonds] Money for this art
249250
[hearts] The shape of my heart
250-
[spades] Swords of a soldier
251251
''');
252252
});
253253

@@ -271,10 +271,10 @@ void main() {
271271
validateUsage(parser, '''
272272
--suit Like in cards
273273
274+
[spades] Swords of a soldier
274275
[clubs] (default) Weapons of war
275276
[diamonds] Money for this art
276277
[hearts] (default) The shape of my heart
277-
[spades] Swords of a soldier
278278
''');
279279
});
280280

0 commit comments

Comments
 (0)