import { red, yellow } from 'chalk'; import { CommandModule } from 'yargs'; import { purgePermissions, validateArgs } from './purge-permissions'; import { GetPurgePermissionsOptions } from './purge-permissions-options'; 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); } }, };