feat(shorebird_cli): improve shorebird apps list display (#202)
This commit is contained in:
@@ -131,8 +131,14 @@ shorebird apps list
|
||||
|
||||
```
|
||||
shorebird apps list
|
||||
my_counter: v1.0.0 (patch #1)
|
||||
my_example: v2.1.0 (patch #2)
|
||||
📱 Apps
|
||||
┌───────────────────┬──────────────────────────────────────┬─────────┬───────┐
|
||||
│ Name │ ID │ Release │ Patch │
|
||||
├───────────────────┼──────────────────────────────────────┼─────────┼───────┤
|
||||
│ Shorebird Counter │ 30370f27-dbf1-4673-8b20-fb096e38dffa │ 1.0.0 │ 1 │
|
||||
├───────────────────┼──────────────────────────────────────┼─────────┼───────┤
|
||||
│ Shorebird Clock │ 05b45471-a5f3-48cd-b26a-da29d95914a7 │ -- │ -- │
|
||||
└───────────────────┴──────────────────────────────────────┴─────────┴───────┘
|
||||
```
|
||||
|
||||
### Run
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:barbecue/barbecue.dart';
|
||||
import 'package:mason_logger/mason_logger.dart';
|
||||
import 'package:shorebird_cli/src/command.dart';
|
||||
import 'package:shorebird_cli/src/shorebird_config_mixin.dart';
|
||||
@@ -40,7 +41,7 @@ class ListAppsCommand extends ShorebirdCommand with ShorebirdConfigMixin {
|
||||
hostedUri: hostedUri,
|
||||
);
|
||||
|
||||
late final List<AppMetadata> apps;
|
||||
final List<AppMetadata> apps;
|
||||
try {
|
||||
apps = await client.getApps();
|
||||
} catch (error) {
|
||||
@@ -48,25 +49,56 @@ class ListAppsCommand extends ShorebirdCommand with ShorebirdConfigMixin {
|
||||
return ExitCode.software.code;
|
||||
}
|
||||
|
||||
logger.info('📱 Apps');
|
||||
|
||||
if (apps.isEmpty) {
|
||||
logger.info('(empty)');
|
||||
return ExitCode.success.code;
|
||||
}
|
||||
|
||||
for (final app in apps) {
|
||||
logger.info(app.prettyPrint());
|
||||
}
|
||||
logger.info(apps.prettyPrint());
|
||||
|
||||
return ExitCode.success.code;
|
||||
}
|
||||
}
|
||||
|
||||
extension on AppMetadata {
|
||||
extension on List<AppMetadata> {
|
||||
String prettyPrint() {
|
||||
final latestReleasePart =
|
||||
latestReleaseVersion != null ? 'v$latestReleaseVersion' : '(empty)';
|
||||
final latestPatchPart =
|
||||
latestPatchNumber != null ? ' (patch #$latestPatchNumber)' : '';
|
||||
return '$displayName: $latestReleasePart$latestPatchPart ($appId)';
|
||||
const cellStyle = CellStyle(
|
||||
paddingLeft: 1,
|
||||
paddingRight: 1,
|
||||
borderBottom: true,
|
||||
borderTop: true,
|
||||
borderLeft: true,
|
||||
borderRight: true,
|
||||
);
|
||||
return Table(
|
||||
cellStyle: cellStyle,
|
||||
header: const TableSection(
|
||||
rows: [
|
||||
Row(
|
||||
cells: [
|
||||
Cell('Name'),
|
||||
Cell('ID'),
|
||||
Cell('Release'),
|
||||
Cell('Patch'),
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
body: TableSection(
|
||||
rows: [
|
||||
for (final app in this)
|
||||
Row(
|
||||
cells: [
|
||||
Cell(app.displayName),
|
||||
Cell(app.appId),
|
||||
Cell(app.latestReleaseVersion ?? '--'),
|
||||
Cell(app.latestPatchNumber?.toString() ?? '--'),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
).render();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,12 +65,23 @@ void main() {
|
||||
latestReleaseVersion: '1.0.0',
|
||||
latestPatchNumber: 1,
|
||||
),
|
||||
const AppMetadata(
|
||||
appId: '05b45471-a5f3-48cd-b26a-da29d95914a7',
|
||||
displayName: 'Shorebird Clock',
|
||||
),
|
||||
];
|
||||
when(() => codePushClient.getApps()).thenAnswer((_) async => apps);
|
||||
expect(await command.run(), ExitCode.success.code);
|
||||
verify(
|
||||
() => logger.info(
|
||||
'''Shorebird Counter: v1.0.0 (patch #1) (30370f27-dbf1-4673-8b20-fb096e38dffa)''',
|
||||
'''
|
||||
┌───────────────────┬──────────────────────────────────────┬─────────┬───────┐
|
||||
│ Name │ ID │ Release │ Patch │
|
||||
├───────────────────┼──────────────────────────────────────┼─────────┼───────┤
|
||||
│ Shorebird Counter │ 30370f27-dbf1-4673-8b20-fb096e38dffa │ 1.0.0 │ 1 │
|
||||
├───────────────────┼──────────────────────────────────────┼─────────┼───────┤
|
||||
│ Shorebird Clock │ 05b45471-a5f3-48cd-b26a-da29d95914a7 │ -- │ -- │
|
||||
└───────────────────┴──────────────────────────────────────┴─────────┴───────┘''',
|
||||
),
|
||||
).called(1);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user