import * as chalk from 'chalk'; import {command, help, namespace, option, param} from 'oo-cli'; import {die} from '../../lib/die'; import {formatVersionState} from '../../lib/formatVersionState'; import {formatReviewStatus} from '../../lib/formatReviewStatus'; import {formatError} from '../../lib/formatError'; import {Rivendell} from '../../lib/Rivendell'; import * as table from 'text-table'; import {styledStringLength} from '../../lib/StringUtils'; import SortDirection = Rivendell.SortDirection; import AppVersion = Rivendell.AppVersion; import AppVersionState = Rivendell.AppVersionState; import App = Rivendell.App; import ReviewStatus = Rivendell.ReviewStatus; @namespace('directory') export class InfoCommand { @param @help('The App ID to look up') public appId!: string; @option('a') @help('The availability zone that will be targeted (default: us)') private availability: string = ''; @command @help('Get information about an app') public async info() { try { await this.render(await Rivendell.fetchApp(this.appId, this.availability)); } catch (e: any) { die(formatError(e)); } } private async render(app: App): Promise { console.log(''); console.log(` ${chalk.bold.underline('General')}\n`); console.log(` ${chalk.cyanBright('id')}\t\t${app.id}`); console.log(` ${chalk.cyanBright('name')}\t${app.name}`); console.log(` ${chalk.cyanBright('created')}\t${app.createdAt}`); console.log(''); // Versions console.log(` ${chalk.bold.underline('Versions')}\n`); const versions = await this.fetchAppVersions(); if (!versions) { console.log(` ${chalk.italic('None')}`); } else { const rows = versions.map((appVersion) => { const r = [ '', appVersion.id.version, formatVersionState(appVersion.state as AppVersionState) ]; if (appVersion.reviewStatus) { r.push(formatReviewStatus(appVersion.reviewStatus as ReviewStatus, appVersion.state as AppVersionState)); } return r; }); const t = table(rows, { hsep: ' '.repeat(4), stringLength: styledStringLength } ); console.log(`\n${t}\n`); } } private async fetchAppVersions(): Promise { return await Rivendell.searchAppVersions( { appId: this.appId, sorts: [ { field: 'createdAt', direction: SortDirection.DESC } ] }, this.availability ); } }