import { Command } from 'commander'; import chalk from 'chalk'; import inquirer from 'inquirer'; import { GenerateReportCommand } from './generateReportCommand'; import { GenerateReportTableCommand } from './generateReportTableCommand'; import { setEntityColumnsKeys, setEntityColumnsSourceId, setEntityColumnsTrackForChanges, setEntityColumnsVisibility, } from '../../../../helpers/entityHelper'; export function SetKeysCommand(): Command { const cmd = new Command('set-keys'); cmd .alias('sk') .description('Set KEYS for the related table of the report.') .option('-i, --id ', 'Search the task by id') .option('-n, --name ', 'Search the task by name') .action(async ({ id, name }: { id?: string; name?: string }) => { await setEntityColumnsKeys(id, name, 'report'); }); return cmd; } export function SetSourceIdCommand(): Command { const cmd = new Command('set-source-id'); cmd .alias('ss') .description('Set SOURCE_ID for the related table of the report.') .option('-i, --id ', 'Search the task by id') .option('-n, --name ', 'Search the task by name') .action(async ({ id, name }: { id?: string; name?: string }) => { await setEntityColumnsSourceId(id, name, 'report'); }); return cmd; } export function TrackChangesCommand(): Command { const cmd = new Command('track-changes'); cmd .alias('tc') .description('Track changes for table columns.') .option('-i, --id ', 'Search the task by id') .option('-n, --name ', 'Search the task by name') .action(async ({ id, name }: { id?: string; name?: string }) => { await setEntityColumnsTrackForChanges(id, name, 'report'); }); return cmd; } export function SetVisibilityCommand(): Command { const cmd = new Command('set-visibility'); cmd .alias('sv') .description("Set Visibility of columns in a Task's Table.") .option('-i, --id ', 'Search the task by id') .option('-n, --name ', 'Search the task by name') .action(async ({ id, name }: { id?: string; name?: string }) => { await setEntityColumnsVisibility(id, name, 'report'); }); return cmd; } export function ReportCommand(): Command { const cmd = new Command('report'); cmd.alias('r').description('Report related commands.'); cmd.hook('preAction', async () => { console.log(''); console.log( chalk.yellow( '⚠︎ WARNING: "report" is obsolete and will not be approved.', ), ); console.log( chalk.yellow( ' Please use "task generate --type REFERENCE" for reference tasks or "task generate --type SYNC" for audit tasks instead.', ), ); console.log(''); const { proceed } = await inquirer.prompt([ { type: 'confirm', name: 'proceed', message: 'Do you still want to continue?', default: false, }, ]); if (!proceed) { process.exit(0); } }); cmd.addCommand(GenerateReportCommand()); cmd.addCommand(GenerateReportTableCommand()); cmd.addCommand(SetSourceIdCommand()); cmd.addCommand(SetKeysCommand()); cmd.addCommand(TrackChangesCommand()); cmd.addCommand(SetVisibilityCommand()); return cmd; }