File tree Expand file tree Collapse file tree 4 files changed +10
-5
lines changed Expand file tree Collapse file tree 4 files changed +10
-5
lines changed Original file line number Diff line number Diff line change 1- ## 2.6.1-wip
1+ ## 2.6.1
22
33* Remove sorting of the ` allowedHelp ` argument in usage output. Ordering will
44 depend on key order for the passed ` Map ` .
55* Fix the repository URL in ` pubspec.yaml ` .
66* Added option ` hideNegatedUsage ` to ` ArgParser.flag() ` allowing a flag to be
77 ` negatable ` without showing it in the usage text.
8+ * Fixed #101 , adding check for mandatory when using ` .option() ` .
89
910## 2.6.0
1011
Original file line number Diff line number Diff line change @@ -81,9 +81,9 @@ class ArgResults {
8181 ///
8282 /// [name] must be a valid flag name in the parser.
8383 bool flag (String name) {
84- var option = _parser.options[name];
84+ final option = _parser.options[name];
8585 if (option == null ) {
86- throw ArgumentError ('Could not find an option named "--$name ".' );
86+ throw ArgumentError ('Could not find a flag named "--$name ".' );
8787 }
8888 if (! option.isFlag) {
8989 throw ArgumentError ('"$name " is not a flag.' );
@@ -95,13 +95,16 @@ class ArgResults {
9595 ///
9696 /// [name] must be a valid option name in the parser.
9797 String ? option (String name) {
98- var option = _parser.options[name];
98+ final option = _parser.options[name];
9999 if (option == null ) {
100100 throw ArgumentError ('Could not find an option named "--$name ".' );
101101 }
102102 if (! option.isSingle) {
103103 throw ArgumentError ('"$name " is a multi-option.' );
104104 }
105+ if (option.mandatory && ! _parsed.containsKey (name)) {
106+ throw ArgumentError ('Option $name is mandatory.' );
107+ }
105108 return option.valueOrDefault (_parsed[name]) as String ? ;
106109 }
107110
Original file line number Diff line number Diff line change 11name : args
2- version : 2.6.1-wip
2+ version : 2.6.1
33description : >-
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.
Original file line number Diff line number Diff line change @@ -621,6 +621,7 @@ void main() {
621621 var results = parser.parse (['-h' ]);
622622 expect (results['help' ], true );
623623 expect (() => results['test' ], throwsA (isA <ArgumentError >()));
624+ expect (() => results.option ('test' ), throwsA (isA <ArgumentError >()));
624625 });
625626 });
626627 });
You can’t perform that action at this time.
0 commit comments