File tree 4 files changed +10
-5
lines changed
4 files changed +10
-5
lines changed Original file line number Diff line number Diff line change 1
- ## 2.6.1-wip
1
+ ## 2.7.0
2
2
3
3
* Remove sorting of the ` allowedHelp ` argument in usage output. Ordering will
4
4
depend on key order for the passed ` Map ` .
5
5
* Fix the repository URL in ` pubspec.yaml ` .
6
6
* Added option ` hideNegatedUsage ` to ` ArgParser.flag() ` allowing a flag to be
7
7
` negatable ` without showing it in the usage text.
8
+ * Fixed #101 , adding check for mandatory when using ` .option() ` .
8
9
9
10
## 2.6.0
10
11
Original file line number Diff line number Diff line change @@ -81,9 +81,9 @@ class ArgResults {
81
81
///
82
82
/// [name] must be a valid flag name in the parser.
83
83
bool flag (String name) {
84
- var option = _parser.options[name];
84
+ final option = _parser.options[name];
85
85
if (option == null ) {
86
- throw ArgumentError ('Could not find an option named "--$name ".' );
86
+ throw ArgumentError ('Could not find a flag named "--$name ".' );
87
87
}
88
88
if (! option.isFlag) {
89
89
throw ArgumentError ('"$name " is not a flag.' );
@@ -95,13 +95,16 @@ class ArgResults {
95
95
///
96
96
/// [name] must be a valid option name in the parser.
97
97
String ? option (String name) {
98
- var option = _parser.options[name];
98
+ final option = _parser.options[name];
99
99
if (option == null ) {
100
100
throw ArgumentError ('Could not find an option named "--$name ".' );
101
101
}
102
102
if (! option.isSingle) {
103
103
throw ArgumentError ('"$name " is a multi-option.' );
104
104
}
105
+ if (option.mandatory && ! _parsed.containsKey (name)) {
106
+ throw ArgumentError ('Option $name is mandatory.' );
107
+ }
105
108
return option.valueOrDefault (_parsed[name]) as String ? ;
106
109
}
107
110
Original file line number Diff line number Diff line change 1
1
name : args
2
- version : 2.6.1-wip
2
+ version : 2.7.0
3
3
description : >-
4
4
Library for defining parsers for parsing raw command-line arguments into a set
5
5
of options and values using GNU and POSIX style options.
Original file line number Diff line number Diff line change @@ -621,6 +621,7 @@ void main() {
621
621
var results = parser.parse (['-h' ]);
622
622
expect (results['help' ], true );
623
623
expect (() => results['test' ], throwsA (isA <ArgumentError >()));
624
+ expect (() => results.option ('test' ), throwsA (isA <ArgumentError >()));
624
625
});
625
626
});
626
627
});
You can’t perform that action at this time.
0 commit comments