Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove sorting of allowedHelp maps #852

Merged
merged 4 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pkgs/args/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## 2.6.1-wip

* Remove sorting of the `allowedHelp` argument in usage output. Ordering will
depend on key order for the passed `Map`.
* Fix the repository URL in `pubspec.yaml`.
* Added option `hideNegatedUsage` to `ArgParser.flag()` allowing a flag to be
`negatable` without showing it in the usage text.
Expand Down
12 changes: 12 additions & 0 deletions pkgs/args/lib/src/arg_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,12 @@ class ArgParser {
///
/// The [allowedHelp] argument is a map from values in [allowed] to
/// documentation for those values that will be included in [usage].
/// The map may include a subset of the allowed values.
/// Additional values that are not in [allowed] should be omitted, however
/// there is no validation.
/// When both [allowed] and [allowedHelp] are passed, only [allowed] will
/// be validated at parse time, and only [allowedHelp] will be included in
/// usage output.
///
/// The [defaultsTo] argument indicates the value this option will have if the
/// user doesn't explicitly pass it in (or `null` by default).
Expand Down Expand Up @@ -231,6 +237,12 @@ class ArgParser {
///
/// The [allowedHelp] argument is a map from values in [allowed] to
/// documentation for those values that will be included in [usage].
/// The map may include a subset of the allowed values.
/// Additional values that are not in [allowed] should be omitted, however
/// there is no validation.
/// When both [allowed] and [allowedHelp] are passed, only [allowed] will
/// be validated at parse time, and only [allowedHelp] will be included in
/// usage output.
///
/// The [defaultsTo] argument indicates the values this option will have if
/// the user doesn't explicitly pass it in (or `[]` by default).
Expand Down
4 changes: 1 addition & 3 deletions pkgs/args/lib/src/usage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,8 @@ class _Usage {
if (option.help != null) _write(2, option.help!);

if (option.allowedHelp != null) {
var allowedNames = option.allowedHelp!.keys.toList();
allowedNames.sort();
_newline();
for (var name in allowedNames) {
for (var name in option.allowedHelp!.keys) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: consider an if case to extract this as a variable and avoid the !

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, did a couple nearby ones as well.

_write(1, _allowedTitle(option, name));
_write(2, option.allowedHelp![name]!);
}
Expand Down
6 changes: 3 additions & 3 deletions pkgs/args/test/usage_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,10 @@ void main() {
validateUsage(parser, '''
--suit Like in cards

[spades] Swords of a soldier
[clubs] Weapons of war
[diamonds] Money for this art
[hearts] The shape of my heart
[spades] Swords of a soldier
''');
});

Expand All @@ -244,10 +244,10 @@ void main() {
validateUsage(parser, '''
--suit Like in cards

[spades] Swords of a soldier
[clubs] (default) Weapons of war
[diamonds] Money for this art
[hearts] The shape of my heart
[spades] Swords of a soldier
''');
});

Expand All @@ -271,10 +271,10 @@ void main() {
validateUsage(parser, '''
--suit Like in cards

[spades] Swords of a soldier
[clubs] (default) Weapons of war
[diamonds] Money for this art
[hearts] (default) The shape of my heart
[spades] Swords of a soldier
''');
});

Expand Down
Loading