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> {
50
50
51
51
@override
52
52
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
+ }
55
60
56
61
_sigint.watch ().listen (_onSigint);
57
62
63
+ late final int exitCode;
58
64
try {
59
65
exitCode = await runCommand (argResults) ?? ExitCode .success.code;
60
66
} catch (error) {
Original file line number Diff line number Diff line change @@ -82,6 +82,26 @@ void main() {
82
82
});
83
83
84
84
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
+
85
105
test ('checks for updates on sigint' , () async {
86
106
final exitCalls = < int > [];
87
107
commandRunner = DartFrogCommandRunner (
You can’t perform that action at this time.
0 commit comments