import {command, help, namespace, option, param} from 'oo-cli'; import {die} from '../../lib/die'; import {formatError} from '../../lib/formatError'; import {Rivendell} from '../../lib/Rivendell'; import Account = Rivendell.Account; import * as chalk from 'chalk'; import * as table from 'text-table'; import {styledStringLength} from '../../lib/StringUtils'; @namespace('accounts') export class WhoisCommand { @param @help('The search term (e.g. 1.web)') public term!: string; @option('a') @help('The availability zone that will be targeted (default: us)') private availability: string = ''; @command @help('Look up basic account information') public async whois() { try { const accounts = await Rivendell.searchAccounts(this.term, this.availability); if (accounts.length) { this.render(accounts); } else { const zone = this.availability || 'us'; console.log(chalk.yellow(`No accounts matching search term '${this.term}' found in ${zone}.`)); } } catch (e: any) { die(formatError(e)); } } private render(accounts: Account[]) { const header = ['id', 'tracker Id', 'name', 'target product'].map((item) => chalk.grey(item)); const rows = accounts.map((account) => [account.id, account.trackerId, account.name, account.accountType]); const t = table( [ header, ...rows ], { hsep: ' '.repeat(8), stringLength: styledStringLength } ); console.log(`\n${t}\n`); } }