Skip to content

Commit

Permalink
Merge branch 'main' into add-source-2
Browse files Browse the repository at this point in the history
Signed-off-by: ふぁ <yuki@yuki0311.com>
  • Loading branch information
fa0311 committed Oct 2, 2024
2 parents d1c1481 + 09c0fca commit 16dc018
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 10 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
matrix:
sdk: [dev]
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938
- uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672
with:
sdk: ${{ matrix.sdk }}
Expand All @@ -47,7 +47,7 @@ jobs:
os: [ubuntu-latest]
sdk: ['3.3', dev]
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938
- uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672
with:
sdk: ${{ matrix.sdk }}
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 2.5.1-wip
## 2.6.0-wip

* Added source argument when throwing a `ArgParserException`.
* Fix inconsistent `FormatException` messages
Expand Down
10 changes: 7 additions & 3 deletions lib/src/arg_parser_exception.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ class ArgParserException extends FormatException {
/// This will be empty if the error was on the root parser.
final List<String> commands;

/// The argument that were being parsed when the error was discovered.
final String? arg;
/// The name of the argument that was being parsed when the error was
/// discovered.
final String? argumentName;

ArgParserException(super.message,
[Iterable<String>? commands, this.arg, super.source, super.offset])
[Iterable<String>? commands,
this.argumentName,
super.source,
super.offset])
: commands = commands == null ? const [] : List.unmodifiable(commands);

/// Returns a string representation of this exception.
Expand Down
2 changes: 1 addition & 1 deletion lib/src/parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class Parser {
throw ArgParserException(
error.message,
[commandName, ...error.commands],
error.arg,
error.argumentName,
error.source,
error.offset);
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: args
version: 2.5.1-wip
version: 2.6.0-wip
description: >-
Library for defining parsers for parsing raw command-line arguments into a set
of options and values using GNU and POSIX style options.
Expand Down
4 changes: 2 additions & 2 deletions test/test_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -349,14 +349,14 @@ void throwsFormat(ArgParser parser, List<String> args, {String? reason}) {
}

void throwsArgParserException(ArgParser parser, List<String> args,
String message, List<String> commands, String arg, int offset) {
String message, List<String> commands, String argumentName, int offset) {
try {
parser.parse(args);
fail('Expected an ArgParserException');
} on ArgParserException catch (e) {
expect(e.message, message);
expect(e.commands, commands);
expect(e.arg, arg);
expect(e.argumentName, argumentName);
expect(e.source, args);
expect(e.offset, offset);
} catch (e) {
Expand Down

0 comments on commit 16dc018

Please sign in to comment.