From 0aaec296359a9e1109badb610439df99f0e51bd3 Mon Sep 17 00:00:00 2001 From: Nate Bosch Date: Tue, 4 Jun 2024 00:25:13 +0000 Subject: [PATCH 1/3] Remove an unnecessary `dynamic` The `dynamic` was used to satisfy the purpose that is more directly expressed with `FutureOr`. --- pkgs/test_core/lib/src/runner/console.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkgs/test_core/lib/src/runner/console.dart b/pkgs/test_core/lib/src/runner/console.dart index b716aad2c..f0d1ee285 100644 --- a/pkgs/test_core/lib/src/runner/console.dart +++ b/pkgs/test_core/lib/src/runner/console.dart @@ -47,9 +47,9 @@ class Console { /// /// The [description] should be a one-line description of the command to print /// in the help output. The [body] callback will be called when the user types - /// the command, and may return a [Future]. + /// the command. void registerCommand( - String name, String description, dynamic Function() body) { + String name, String description, FutureOr Function() body) { if (_commands.containsKey(name)) { throw ArgumentError('The console already has a command named "$name".'); } @@ -111,7 +111,7 @@ class _Command { final String description; /// The callback to run when the command is invoked. - final Function body; + final FutureOr Function() body; _Command(this.name, this.description, this.body); } From 6c22b9cbb4e8ef64dd46608df629725156b7a15a Mon Sep 17 00:00:00 2001 From: Nate Bosch Date: Tue, 4 Jun 2024 19:22:35 +0000 Subject: [PATCH 2/3] Drop the _Command class --- pkgs/test_core/lib/src/runner/console.dart | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/pkgs/test_core/lib/src/runner/console.dart b/pkgs/test_core/lib/src/runner/console.dart index f0d1ee285..761827f26 100644 --- a/pkgs/test_core/lib/src/runner/console.dart +++ b/pkgs/test_core/lib/src/runner/console.dart @@ -13,7 +13,8 @@ import '../util/io.dart'; /// An interactive console for taking user commands. class Console { /// The registered commands. - final _commands = {}; + final _commands = Function() body})>{}; /// The pending next line of standard input, if we're waiting on one. CancelableOperation? _nextLine; @@ -54,7 +55,7 @@ class Console { throw ArgumentError('The console already has a command named "$name".'); } - _commands[name] = _Command(name, description, body); + _commands[name] = (name: name, description: description, body: body); } /// Starts running the console. @@ -101,17 +102,3 @@ class Console { } } } - -/// An individual console command. -class _Command { - /// The name of the command. - final String name; - - /// The single-line description of the command. - final String description; - - /// The callback to run when the command is invoked. - final FutureOr Function() body; - - _Command(this.name, this.description, this.body); -} From 3592bfc414def6fbdc150431f0dcf26f69548526 Mon Sep 17 00:00:00 2001 From: Nate Bosch Date: Tue, 4 Jun 2024 19:44:48 +0000 Subject: [PATCH 3/3] Add typedef --- pkgs/test_core/lib/src/runner/console.dart | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pkgs/test_core/lib/src/runner/console.dart b/pkgs/test_core/lib/src/runner/console.dart index 761827f26..3a4d6facf 100644 --- a/pkgs/test_core/lib/src/runner/console.dart +++ b/pkgs/test_core/lib/src/runner/console.dart @@ -13,8 +13,7 @@ import '../util/io.dart'; /// An interactive console for taking user commands. class Console { /// The registered commands. - final _commands = Function() body})>{}; + final _commands = {}; /// The pending next line of standard input, if we're waiting on one. CancelableOperation? _nextLine; @@ -102,3 +101,9 @@ class Console { } } } + +typedef _Command = ({ + String name, + String description, + FutureOr Function() body, +});