import * as chalk from 'chalk'; import {command, help, namespace, option, param} from 'oo-cli'; import {die} from '../../lib/die'; import {Rivendell} from '../../lib/Rivendell'; import {formatError} from '../../lib/formatError'; @namespace('directory') export class InstallCommand { @param @help('The App ID and version (e.g. my_app@1.0.0)') public appVersion!: string; @param @help('The Tracker ID of the account to install into') public trackerId!: string; @option('a') @help('The availability zone that will be targeted (default: us)') private availability: string = ''; @command @help('Install a specific app version into an account') public async install() { if (!/[\w-]+@\d+\.\d+\.\d+(?:-\w+\.\d+)?/.test(this.appVersion)) { return die('appVersion is required in the format of app@1.0.0'); } const [appId, version] = this.appVersion.split('@'); try { const install = await Rivendell.install(appId, version, this.trackerId, this.availability); console.log(chalk.green(`Installed ${appId}@${version} for ${this.trackerId} ` + `with install id ${install.id} in ${this.availability || 'us'}`)); } catch (e: any) { die(formatError(e)); } } }