import { ensureError } from '@axinom/mosaic-service-common'; import chalk from 'chalk'; import { CommandModule } from 'yargs'; import { exitCode } from '../../common'; import { callUnpublishPilet } from './unpublish-pilet'; import { UnpublishPiletOptions } from './unpublish-pilet-options'; export const unpublishPilet: CommandModule = { command: 'unpublish-pilet', describe: 'Unpublishes a pilet from Mosaic Micro Frontend Service', builder: (yargs) => yargs .option('tenantId', { alias: ['t'], describe: 'Tenant ID', string: true, demandOption: true, }) .option('environmentId', { alias: ['e'], describe: 'Environment ID', string: true, demandOption: true, }) .option('apiKey', { alias: ['a', 'apiKey'], describe: 'Base 64 encoded credentials for a Service Account with permission Pilet: Delete', string: true, demandOption: true, }) .option('microFrontendServiceBaseUrl', { alias: ['m', 'microFrontendServiceBaseUrl'], describe: 'Base URL of Mosaic Micro Frontend Service.', string: true, demandOption: true, }) .option('name', { alias: ['n'], describe: 'Name of the pilet to unpublish.', string: true, demandOption: true, }), handler: async (options: UnpublishPiletOptions): Promise => { try { const result = await callUnpublishPilet(options); if (result) { console.log(chalk.green('Pilet successfully unpublished.')); console.log( chalk.green( JSON.stringify({ tenantId: options.tenantId, environmentId: options.environmentId, piletName: options.name, }), ), ); } } catch (e) { const error = ensureError(e); console.log( chalk.red('Command failed:'), error.message, // eslint-disable-next-line @typescript-eslint/no-explicit-any (error as any).response.data.message, ); process.exit(exitCode); } }, };