-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
991e138
commit afce55c
Showing
9 changed files
with
174 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export 'create/create.dart'; | ||
export 'packages.dart'; | ||
export 'test/test.dart'; | ||
export 'update.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import 'package:args/command_runner.dart'; | ||
import 'package:mason/mason.dart' hide packageVersion; | ||
import 'package:pub_updater/pub_updater.dart'; | ||
import 'package:very_good_cli/src/command_runner.dart'; | ||
import 'package:very_good_cli/src/version.dart'; | ||
|
||
/// {@template update_command} | ||
/// `very_good update` command which updates very_good cli. | ||
/// {@endtemplate} | ||
class UpdateCommand extends Command<int> { | ||
/// {@macro update_command} | ||
UpdateCommand({ | ||
Logger? logger, | ||
PubUpdater? pubUpdater, | ||
}) : _logger = logger ?? Logger(), | ||
_pubUpdater = pubUpdater ?? PubUpdater(); | ||
|
||
final Logger _logger; | ||
final PubUpdater _pubUpdater; | ||
|
||
@override | ||
String get description => 'Update Very Good CLI.'; | ||
|
||
@override | ||
String get name => 'update'; | ||
|
||
@override | ||
Future<int> run() async { | ||
final updateCheckProgress = _logger.progress('Checking for updates'); | ||
late final String latestVersion; | ||
try { | ||
latestVersion = await _pubUpdater.getLatestVersion(packageName); | ||
} catch (error) { | ||
updateCheckProgress.fail(); | ||
_logger.err('$error'); | ||
return ExitCode.software.code; | ||
} | ||
updateCheckProgress.complete('Checked for updates'); | ||
|
||
final isUpToDate = packageVersion == latestVersion; | ||
if (isUpToDate) { | ||
_logger.info('Very Good CLI is already at the latest version.'); | ||
return ExitCode.success.code; | ||
} | ||
|
||
final updateProgress = _logger.progress('Updating to $latestVersion'); | ||
try { | ||
await _pubUpdater.update(packageName: packageName); | ||
} catch (error) { | ||
updateProgress.fail(); | ||
_logger.err('$error'); | ||
return ExitCode.software.code; | ||
} | ||
updateProgress.complete('Updated to $latestVersion'); | ||
|
||
return ExitCode.success.code; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.