-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
maestro update
command and automatically inform about new versi…
…on (#85) * add `maestro update` command and automatically inform about new version * Update packages/maestro_cli/lib/src/command_runner.dart * don't fetch latest version when not needed Co-authored-by: Marcin Wojnarowski <[email protected]>
- Loading branch information
1 parent
be6fccd
commit 77d4465
Showing
5 changed files
with
129 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
|
||
# make is a convenience command for running common Gradle tasks. | ||
|
||
./gradlew assembleDebugAndroidTest | ||
./gradlew installDebugAndroidTest | ||
./gradlew install |
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
53 changes: 53 additions & 0 deletions
53
packages/maestro_cli/lib/src/features/update/update_command.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,53 @@ | ||
import 'package:args/command_runner.dart'; | ||
import 'package:pub_updater/pub_updater.dart'; | ||
|
||
import '../../common/common.dart'; | ||
|
||
class UpdateCommand extends Command<int> { | ||
UpdateCommand() : _pubUpdater = PubUpdater(); | ||
|
||
final PubUpdater _pubUpdater; | ||
|
||
@override | ||
String get name => 'update'; | ||
|
||
@override | ||
String get description => 'Updates maestro CLI.'; | ||
|
||
@override | ||
Future<int> run() async { | ||
final isLatestVersion = await _pubUpdater.isUpToDate( | ||
packageName: maestroCliPackage, | ||
currentVersion: version, | ||
); | ||
|
||
if (!isLatestVersion) { | ||
final latestVersion = await _pubUpdater.getLatestVersion( | ||
maestroCliPackage, | ||
); | ||
await _update(latestVersion); | ||
} else { | ||
log.info( | ||
'You already have the newest version of $maestroCliPackage ($version)', | ||
); | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
Future<void> _update(String latestVersion) async { | ||
final progress = log.progress( | ||
'Updating $maestroCliPackage to version $latestVersion', | ||
); | ||
|
||
try { | ||
await _pubUpdater.update(packageName: maestroCliPackage); | ||
progress.complete('Updated $maestroCliPackage to version $latestVersion'); | ||
} catch (err) { | ||
progress.fail( | ||
'Failed to update $maestroCliPackage to version $latestVersion', | ||
); | ||
rethrow; | ||
} | ||
} | ||
} |
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