From bd6e76d081b2f4c409c1efd6bcaa2aa59f4df5fb Mon Sep 17 00:00:00 2001 From: Justin Baumann Date: Sat, 4 Nov 2023 15:15:46 +0100 Subject: [PATCH] simplify --- sidekick_core/lib/sidekick_core.dart | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/sidekick_core/lib/sidekick_core.dart b/sidekick_core/lib/sidekick_core.dart index 0fac5c13..732d28b9 100644 --- a/sidekick_core/lib/sidekick_core.dart +++ b/sidekick_core/lib/sidekick_core.dart @@ -284,7 +284,7 @@ class SidekickCommandRunner extends CompletionCommandRunner { final unmount = mount(debugName: args.join(' ')); ArgResults? parsedArgs; - Future? updateCheck; + Future? updateCheck; try { parsedArgs = parse(args); @@ -322,7 +322,11 @@ class SidekickCommandRunner extends CompletionCommandRunner { } try { - (await updateCheck)?.call(); + // print warning if the user didn't fully update their CLI + _checkCliVersionIntegrity(); + await updateCheck?.then((result) { + if (result != null) printerr(result); + }); } finally { unmount(); } @@ -330,8 +334,7 @@ class SidekickCommandRunner extends CompletionCommandRunner { } /// Print a warning if the CLI isn't up to date - Future _checkForUpdates() async { - void Function()? updateCheck; + Future _checkForUpdates() async { try { final updateFuture = VersionChecker.isDependencyUpToDate( package: SidekickContext.sidekickPackage, @@ -342,19 +345,13 @@ class SidekickCommandRunner extends CompletionCommandRunner { final isUpToDate = await updateFuture.timeout(const Duration(seconds: 3)); if (!isUpToDate) { - updateCheck = () => printerr( - '${yellow('Update available!')}\n' - 'Run ${cyan('${SidekickContext.cliName} sidekick update')} to update your CLI.', - ); + return '${yellow('Update available!')}\n' + 'Run ${cyan('${SidekickContext.cliName} sidekick update')} to update your CLI.'; } } catch (_) { /* ignore */ } - return () { - // print warning if the user didn't fully update their CLI - _checkCliVersionIntegrity(); - updateCheck?.call(); - }; + return null; } /// Print a warning if the user manually updated the sidekick_core