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'; import Webhook = Rivendell.Webhook; @namespace('directory') export class ListGlobalFunctionsCommand { @param @help('The App ID (e.g. my_app)') public appId!: string; @option('a') @help('The availability zone that will be targeted (default: us)') private availability: string = ''; @command('list-global-functions') @help('List the global functions exposed by an app') public async listGlobalFunctions() { try { this.render(await Rivendell.searchWebhooks({ appId: this.appId, appInstallId: 0, includeInternal: true, includeDisabled: true }, this.availability)); } catch (e: any) { die(formatError(e)); } } private render(webhooks: Webhook[]) { if (webhooks.length === 0) { console.log(chalk.yellow(`${this.appId} does not contain global functions.`)); } else { webhooks.forEach((webhook) => { const attrs = webhook.attributes; const caveats = []; if (attrs.internal) { caveats.push('internal'); } if (!attrs.enabled) { caveats.push('disabled'); } if (caveats.length === 0) { console.log(webhook.url); } else { console.log(chalk.yellow(`${webhook.url} (${caveats.join(', ')})`)); } }); } } }