-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(shorebird_cli): add
shorebird flutter versions list
(#1064)
- Loading branch information
Showing
7 changed files
with
158 additions
and
1 deletion.
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
export 'flutter_command.dart'; | ||
export 'versions/versions.dart'; |
5 changes: 4 additions & 1 deletion
5
packages/shorebird_cli/lib/src/commands/flutter/flutter_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
19 changes: 19 additions & 0 deletions
19
packages/shorebird_cli/lib/src/commands/flutter/versions/flutter_versions_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,19 @@ | ||
import 'package:shorebird_cli/src/command.dart'; | ||
import 'package:shorebird_cli/src/commands/commands.dart'; | ||
|
||
/// {@template flutter_versions_command} | ||
/// `shorebird flutter versions` | ||
/// Manage your Shorebird Flutter versions. | ||
/// {@endtemplate} | ||
class FlutterVersionsCommand extends ShorebirdCommand { | ||
/// {@macro flutter_versions_command} | ||
FlutterVersionsCommand() { | ||
addSubcommand(FlutterVersionsListCommand()); | ||
} | ||
|
||
@override | ||
String get description => 'Manage your Shorebird Flutter versions.'; | ||
|
||
@override | ||
String get name => 'versions'; | ||
} |
39 changes: 39 additions & 0 deletions
39
packages/shorebird_cli/lib/src/commands/flutter/versions/flutter_versions_list_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,39 @@ | ||
import 'package:mason_logger/mason_logger.dart'; | ||
import 'package:shorebird_cli/src/command.dart'; | ||
import 'package:shorebird_cli/src/logger.dart'; | ||
import 'package:shorebird_cli/src/shorebird_flutter.dart'; | ||
|
||
/// {@template flutter_versions_list_command} | ||
/// `shorebird flutter versions list` | ||
/// List available Flutter versions. | ||
/// {@endtemplate} | ||
class FlutterVersionsListCommand extends ShorebirdCommand { | ||
/// {@macro flutter_versions_list_command} | ||
FlutterVersionsListCommand(); | ||
|
||
@override | ||
String get description => 'List available Flutter versions.'; | ||
|
||
@override | ||
String get name => 'list'; | ||
|
||
@override | ||
Future<int> run() async { | ||
final progress = logger.progress('Fetching Flutter versions'); | ||
final List<String> versions; | ||
try { | ||
versions = await shorebirdFlutter.getVersions(); | ||
progress.complete(); | ||
} catch (error) { | ||
progress.fail('Failed to fetch Flutter versions.'); | ||
logger.err('$error'); | ||
return ExitCode.software.code; | ||
} | ||
|
||
logger.info('📦 Flutter Versions'); | ||
for (final version in versions.reversed) { | ||
logger.info(version); | ||
} | ||
return ExitCode.success.code; | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
packages/shorebird_cli/lib/src/commands/flutter/versions/versions.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,2 @@ | ||
export 'flutter_versions_command.dart'; | ||
export 'flutter_versions_list_command.dart'; |
15 changes: 15 additions & 0 deletions
15
packages/shorebird_cli/test/src/commands/flutter/versions/flutter_versions_command_test.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,15 @@ | ||
import 'package:shorebird_cli/src/commands/commands.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
void main() { | ||
group(FlutterVersionsCommand, () { | ||
test('has correct name and description', () { | ||
final command = FlutterVersionsCommand(); | ||
expect(command.name, equals('versions')); | ||
expect( | ||
command.description, | ||
equals('Manage your Shorebird Flutter versions.'), | ||
); | ||
}); | ||
}); | ||
} |
78 changes: 78 additions & 0 deletions
78
.../shorebird_cli/test/src/commands/flutter/versions/flutter_versions_list_command_test.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,78 @@ | ||
import 'package:mason_logger/mason_logger.dart'; | ||
import 'package:mocktail/mocktail.dart'; | ||
import 'package:scoped/scoped.dart'; | ||
import 'package:shorebird_cli/src/commands/commands.dart'; | ||
import 'package:shorebird_cli/src/logger.dart'; | ||
import 'package:shorebird_cli/src/shorebird_flutter.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
class _MockLogger extends Mock implements Logger {} | ||
|
||
class _MockProgress extends Mock implements Progress {} | ||
|
||
class _MockShorebirdFlutter extends Mock implements ShorebirdFlutter {} | ||
|
||
void main() { | ||
group(FlutterVersionsListCommand, () { | ||
late Progress progress; | ||
late Logger logger; | ||
late ShorebirdFlutter shorebirdFlutter; | ||
late FlutterVersionsListCommand command; | ||
|
||
R runWithOverrides<R>(R Function() body) { | ||
return runScoped( | ||
body, | ||
values: { | ||
loggerRef.overrideWith(() => logger), | ||
shorebirdFlutterRef.overrideWith(() => shorebirdFlutter), | ||
}, | ||
); | ||
} | ||
|
||
setUp(() { | ||
progress = _MockProgress(); | ||
logger = _MockLogger(); | ||
shorebirdFlutter = _MockShorebirdFlutter(); | ||
command = runWithOverrides(FlutterVersionsListCommand.new); | ||
|
||
when(() => logger.progress(any())).thenReturn(progress); | ||
}); | ||
|
||
test('has correct name and description', () { | ||
expect(command.name, equals('list')); | ||
expect(command.description, equals('List available Flutter versions.')); | ||
}); | ||
|
||
test('exits with code 70 when unable to determine Flutter versions', | ||
() async { | ||
when(() => shorebirdFlutter.getVersions()).thenThrow('error'); | ||
await expectLater( | ||
runWithOverrides(command.run), | ||
completion(equals(ExitCode.software.code)), | ||
); | ||
verifyInOrder([ | ||
() => logger.progress('Fetching Flutter versions'), | ||
() => progress.fail('Failed to fetch Flutter versions.'), | ||
() => logger.err('error'), | ||
]); | ||
}); | ||
|
||
test('exits with code 0 when able to determine Flutter versions', () async { | ||
const versions = ['1.0.0', '1.0.1']; | ||
when( | ||
() => shorebirdFlutter.getVersions(), | ||
).thenAnswer((_) async => versions); | ||
await expectLater( | ||
runWithOverrides(command.run), | ||
completion(equals(ExitCode.success.code)), | ||
); | ||
verifyInOrder([ | ||
() => logger.progress('Fetching Flutter versions'), | ||
() => progress.complete(), | ||
() => logger.info('📦 Flutter Versions'), | ||
() => logger.info('1.0.1'), | ||
() => logger.info('1.0.0'), | ||
]); | ||
}); | ||
}); | ||
} |