File tree Expand file tree Collapse file tree 2 files changed +28
-2
lines changed
Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -50,11 +50,17 @@ class DartFrogCommandRunner extends CommandRunner<int> {
5050
5151 @override
5252 Future <int > run (Iterable <String > args) async {
53- final argResults = parse (args);
54- late final int exitCode;
53+ late final ArgResults argResults;
54+ try {
55+ argResults = parse (args);
56+ } on UsageException catch (error) {
57+ _logger.err ('$error ' );
58+ return ExitCode .usage.code;
59+ }
5560
5661 _sigint.watch ().listen (_onSigint);
5762
63+ late final int exitCode;
5864 try {
5965 exitCode = await runCommand (argResults) ?? ExitCode .success.code;
6066 } catch (error) {
Original file line number Diff line number Diff line change @@ -82,6 +82,26 @@ void main() {
8282 });
8383
8484 group ('run' , () {
85+ test ('shows usage when invalid option is passed' , () async {
86+ final exitCode = await commandRunner.run (['--invalid-option' ]);
87+ expect (exitCode, ExitCode .usage.code);
88+ verify (
89+ () => logger.err (
90+ any (
91+ that: predicate <String >((message) {
92+ final containsError = message.contains (
93+ 'Could not find an option named "invalid-option".' ,
94+ );
95+ final containsUsage = message.contains (
96+ 'Usage: dart_frog <command> [arguments]' ,
97+ );
98+ return containsError && containsUsage;
99+ }),
100+ ),
101+ ),
102+ ).called (1 );
103+ });
104+
85105 test ('checks for updates on sigint' , () async {
86106 final exitCalls = < int > [];
87107 commandRunner = DartFrogCommandRunner (
You can’t perform that action at this time.
0 commit comments