Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Baumann committed Nov 4, 2023
1 parent 0bd0153 commit bd6e76d
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions sidekick_core/lib/sidekick_core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ class SidekickCommandRunner<T> extends CompletionCommandRunner<T> {
final unmount = mount(debugName: args.join(' '));

ArgResults? parsedArgs;
Future<void Function()?>? updateCheck;
Future<String?>? updateCheck;

try {
parsedArgs = parse(args);
Expand Down Expand Up @@ -322,16 +322,19 @@ class SidekickCommandRunner<T> extends CompletionCommandRunner<T> {
}

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();
}
}
}

/// Print a warning if the CLI isn't up to date
Future<void Function()> _checkForUpdates() async {
void Function()? updateCheck;
Future<String?> _checkForUpdates() async {
try {
final updateFuture = VersionChecker.isDependencyUpToDate(
package: SidekickContext.sidekickPackage,
Expand All @@ -342,19 +345,13 @@ class SidekickCommandRunner<T> extends CompletionCommandRunner<T> {
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
Expand Down

0 comments on commit bd6e76d

Please sign in to comment.