From 0220589c7ae151b429cb6f825a6e36dc1eb5315d Mon Sep 17 00:00:00 2001 From: Felix Angelov Date: Wed, 29 Mar 2023 15:30:50 -0500 Subject: [PATCH] feat(shorebird_cli): improve `shorebird apps list` display (#202) --- packages/shorebird_cli/README.md | 10 +++- .../src/commands/apps/list_apps_command.dart | 52 +++++++++++++++---- .../commands/apps/list_apps_command_test.dart | 13 ++++- 3 files changed, 62 insertions(+), 13 deletions(-) diff --git a/packages/shorebird_cli/README.md b/packages/shorebird_cli/README.md index 7d976614..c13ff0a6 100644 --- a/packages/shorebird_cli/README.md +++ b/packages/shorebird_cli/README.md @@ -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 diff --git a/packages/shorebird_cli/lib/src/commands/apps/list_apps_command.dart b/packages/shorebird_cli/lib/src/commands/apps/list_apps_command.dart index 52846b1b..fb64faa3 100644 --- a/packages/shorebird_cli/lib/src/commands/apps/list_apps_command.dart +++ b/packages/shorebird_cli/lib/src/commands/apps/list_apps_command.dart @@ -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 apps; + final List 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 { 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(); } } diff --git a/packages/shorebird_cli/test/src/commands/apps/list_apps_command_test.dart b/packages/shorebird_cli/test/src/commands/apps/list_apps_command_test.dart index 2c64ade4..977dd371 100644 --- a/packages/shorebird_cli/test/src/commands/apps/list_apps_command_test.dart +++ b/packages/shorebird_cli/test/src/commands/apps/list_apps_command_test.dart @@ -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); });