Skip to content

Commit d5f481d

Browse files
committed
Also support mandatory top level options
1 parent 13000b5 commit d5f481d

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

pkgs/args/lib/src/parser.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ class Parser {
122122
}
123123

124124
// Check if mandatory and invoke existing callbacks.
125-
final ignoreMandatoryOptions = _results.containsKey('help');
125+
final ignoreMandatoryOptions =
126+
_results.containsKey('help') || command?.name == 'help';
126127
_grammar.options.forEach((name, option) {
127128
var parsedOption = _results[name];
128129

pkgs/args/test/command_runner_test.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,24 @@ Global options:
799799
Available commands:
800800
mandatory-option-command A command with a mandatory option
801801
802+
Run "test help <command>" for more information about a command.
803+
'''));
804+
});
805+
806+
test('mandatory global options do not interfere with help command', () {
807+
runner.argParser.addOption('mandatory', mandatory: true);
808+
expect(() => runner.run(['help']), prints('''
809+
A test command runner.
810+
811+
Usage: test <command> [arguments]
812+
813+
Global options:
814+
-h, --help Print this usage information.
815+
--mandatory (mandatory)
816+
817+
Available commands:
818+
help Display help information for test.
819+
802820
Run "test help <command>" for more information about a command.
803821
'''));
804822
});

0 commit comments

Comments
 (0)