import chalk from 'chalk'; import type { CommandModule } from 'yargs'; import type { GetPurgePermissionsOptions } from './purge-permissions-options.js'; import { purgePermissions, validateArgs } from './purge-permissions.js'; const { red, yellow } = chalk; export const purgePermissionsCommand: CommandModule< unknown, GetPurgePermissionsOptions > = { builder: (yargs) => { return yargs .option('serviceId', { describe: 'Service ID the permissions should be purged from. If no value is explicity given, environment variable SERVICE_ID will be used.', alias: 'i', string: true, }) .option('idServiceAuthBaseURL', { describe: 'ID Service Authentication Endpoint Base URL. If no value is explicity given, environment variable ID_SERVICE_AUTH_BASE_URL will be used.', alias: 'a', string: true, }) .option('clientId', { describe: 'Client ID of a Service Account which has Synchronize Permission permission assigned. If no value is explicity given, environment variable SERVICE_ACCOUNT_CLIENT_ID will be used.', alias: 'c', string: true, }) .option('clientSecret', { describe: 'Client Secret for the above Client ID. If no value is explicity given, environment variable SERVICE_ACCOUNT_CLIENT_SECRET will be used.', alias: 's', string: true, }); }, handler: async (args) => { const [validatedArgs, errorMessages] = validateArgs(args); if (errorMessages.length > 0) { console.log( red('Some required arguments are missing and/or are erroneous.'), ); errorMessages.map((message) => { console.log(yellow(`${message}`)); }); console.log(); } else { await purgePermissions(validatedArgs); } }, };