import { Command } from 'commander'; import { findTable, getAssociation, searchTask, } from '../../helpers/profileGeneratorHelper'; import { paddingList } from '../../helpers/paddingList'; import { readVariableValue } from '../../helpers/variablesHelper'; async function showTaskInfo(taskName: string) { const yml: any = await searchTask(taskName); const genericFields = [ 'id', 'name', 'priority', 'valueTableName', 'ignoreRemoval', 'ignoreChange', ]; const info = [ ...genericFields.map((f) => { return { field: f, variableName: yml[f], variableValue: readVariableValue(yml[f]), }; }), ]; console.log(`Basic Info`); console.log( info .map((f, i) => { return f.variableName === f.variableValue ? `${i + 1}. ${f.field}: ${f.variableName}` : `${i + 1}. ${f.field}: ${f.variableName} (${f.variableValue})`; }) .join('\r\n'), ); const allAssociations = getAssociation(); const taskAssociation = allAssociations.objectAssociations[yml.id]; const tableYml = await findTable(taskAssociation.table?.id); const fields = (tableYml || {}).columns || {}; const fieldInfos = Object.keys(fields).map((k, i) => `${i + 1}. ${k}`); console.log(`\r\nProperties: ${paddingList(fieldInfos)}`); console.log(`__file_path: ${yml.__file_path}`); } export function ShowProfileEntityInfoCommand(): Command { const cmd = new Command('show-info') .alias('si') .description('Show information of an entity in profile.') .option( '-t, --type ', 'Entity type, e.g.: task, puller, pusher, report', ) .option( '-n, --name ', "Entity name, e.g.: product, 'sales order', ...", ) .action(async ({ type, name }) => { switch (type) { case 'task': showTaskInfo(name); break; default: console.error( `Entity type ${type} is not support. Currently support: task, puller, pusher, report`, ); } }); return cmd; }