import * as chalk from 'chalk'; import {command, help, namespace, param, required, option} from 'oo-cli'; import {appContext} from '../../lib/AppContext'; import {die} from '../../lib/die'; import {Rivendell} from '../../lib/Rivendell'; import {formatError} from '../../lib/formatError'; import LogLevelRecord = Rivendell.LogLevelRecord; @namespace('app') export class GetLogLevelCommand { @param @required @help('The App ID and version') public appVersion!: string; @option('trackerId') @help('The Tracker ID of the installed account (required for developers). If not provided, returns default log level for the app version') public trackerId?: string; @option('a') @help('The availability zone that will be targeted (default: us)') private availability: string = ''; @command('get-log-level') @help('Get the logLevel of a particular app version or an installation') public async getLogLevel() { try { const context = appContext(this.appVersion); if (!context.appId || !context.version) { return die('App ID and version are required'); } if (!this.trackerId && !await Rivendell.isAdmin()) { die('Tracker ID must be specified for developer role.'); } const logLevelRecord = await Rivendell.getLogLevel( this.availability, context.appId, context.version, this.trackerId); this.render(logLevelRecord); } catch (e: any) { die(formatError(e)); } } private render(record: LogLevelRecord) { if (record.trackerId) { console.log(chalk.green(`install log level is currently set to ${record.logLevel}`)); } else { console.log(chalk.green(`${this.appVersion} log level is currently set to ${record.logLevel}`)); } } }