listProjects static method
Future<void>
listProjects(
- Client cloudApiClient, {
- required CommandLogger logger,
- bool showArchived = false,
Implementation
static Future<void> listProjects(
final Client cloudApiClient, {
required final CommandLogger logger,
final bool showArchived = false,
}) async {
late List<Project> projects;
try {
projects = await cloudApiClient.projects.listProjects();
} on Exception catch (e, s) {
throw FailureException.nested(e, s, 'Request to list projects failed');
}
final activeProjects = showArchived
? projects
: projects.where((final p) => p.archivedAt == null);
if (activeProjects.isEmpty) {
logger.info('No projects available.');
return;
}
final tablePrinter = TablePrinter();
tablePrinter.addHeaders([
'Project Id',
'Created At',
if (showArchived) 'Deleted At',
]);
for (final project in activeProjects.sortedBy((final p) => p.createdAt)) {
tablePrinter.addRow([
project.cloudProjectId,
project.createdAt.toString().substring(0, 19),
if (showArchived) project.archivedAt?.toString().substring(0, 19),
]);
}
tablePrinter.writeLines(logger.line);
}