import {command, help, namespace} from 'oo-cli'; import {die} from '../../lib/die'; import {formatError} from '../../lib/formatError'; import {Rivendell} from '../../lib/Rivendell'; import Shard = Rivendell.Shard; import * as chalk from 'chalk'; import * as table from 'text-table'; import {styledStringLength} from '../../lib/StringUtils'; @namespace('availability') export class ListCommand { @command @help('List all availability zones') public async list() { try { this.render(await Rivendell.shards()); } catch (e: any) { die(formatError(e)); } } private render(accounts: Shard[]) { const header = ['Name', 'Description'].map((item) => chalk.grey(item)); const rows = accounts.map((shard) => [shard.id, shard.description]); const t = table( [ header, ...rows ], { hsep: ' '.repeat(8), stringLength: styledStringLength } ); console.log(`\n${t}\n`); } }