@@ -576,6 +576,86 @@ async function showHelp() {
576576 await pause ( ) ;
577577}
578578
579+ function getArgValue ( name ) {
580+ const prefix = `--${ name } =` ;
581+ const found = process . argv . find ( a => a . startsWith ( prefix ) ) ;
582+ return found ? found . substring ( prefix . length ) : null ;
583+ }
584+
585+ async function runValidateNonInteractive ( filePath , type ) {
586+ if ( ! filePath || ! type ) {
587+ process . exit ( 2 ) ;
588+ return ;
589+ }
590+ try {
591+ if ( process . pkg ) {
592+ const options = { configFilePath : path . join ( APP_ROOT , 'config' , 'dbinfo.json' ) , variables : { } } ;
593+ if ( type === 'XML' ) options . xmlFilePath = filePath ; else options . queryFilePath = filePath ;
594+ const ok = await excelCli . validateQueryFile ( options ) ;
595+ if ( ! ok ) throw new Error ( 'validation failed' ) ;
596+ } else {
597+ const cmd = type === 'XML'
598+ ? `node src/excel-cli.js validate --xml "${ filePath } "`
599+ : `node src/excel-cli.js validate --query "${ filePath } "` ;
600+ execSync ( cmd , { cwd : APP_ROOT , stdio : 'inherit' , encoding : 'utf8' } ) ;
601+ }
602+ process . exit ( 0 ) ;
603+ } catch ( e ) {
604+ process . exit ( 1 ) ;
605+ }
606+ }
607+
608+ async function runTestNonInteractive ( ) {
609+ try {
610+ if ( process . pkg ) {
611+ const configPath = path . join ( APP_ROOT , 'config' , 'dbinfo.json' ) ;
612+ await excelCli . testAllDatabaseConnections ( configPath ) ;
613+ } else {
614+ execSync ( 'node src/excel-cli.js list-dbs' , { cwd : APP_ROOT , stdio : 'inherit' , encoding : 'utf8' } ) ;
615+ }
616+ process . exit ( 0 ) ;
617+ } catch ( e ) {
618+ process . exit ( 1 ) ;
619+ }
620+ }
621+
622+ async function runExportNonInteractive ( filePath , type ) {
623+ if ( ! filePath || ! type ) {
624+ process . exit ( 2 ) ;
625+ return ;
626+ }
627+ try {
628+ if ( process . pkg ) {
629+ const originalArgv = process . argv ;
630+ const originalExit = process . exit ;
631+ process . exit = ( code ) => { if ( code && code !== 0 ) throw new Error ( String ( code ) ) ; } ;
632+ const filteredArgs = originalArgv . slice ( 2 ) . filter ( arg => ! arg . startsWith ( '--lang=' ) ) ;
633+ process . argv = type === 'XML'
634+ ? [ 'node' , 'src/excel-cli.js' , 'export' , '--xml' , filePath , ...filteredArgs ]
635+ : [ 'node' , 'src/excel-cli.js' , 'export' , '--query' , filePath , ...filteredArgs ] ;
636+ try { await excelCli . main ( ) ; }
637+ finally { process . argv = originalArgv ; process . exit = originalExit ; }
638+ } else {
639+ const cmd = type === 'XML'
640+ ? `node src/excel-cli.js export --xml "${ filePath } "`
641+ : `node src/excel-cli.js export --query "${ filePath } "` ;
642+ execSync ( cmd , { cwd : APP_ROOT , stdio : 'inherit' , encoding : 'utf8' } ) ;
643+ }
644+ process . exit ( 0 ) ;
645+ } catch ( e ) {
646+ process . exit ( 1 ) ;
647+ }
648+ }
649+
650+ async function runHelpNonInteractive ( ) {
651+ try {
652+ await showHelp ( ) ;
653+ process . exit ( 0 ) ;
654+ } catch ( e ) {
655+ process . exit ( 1 ) ;
656+ }
657+ }
658+
579659// 메인 메뉴
580660async function mainMenu ( ) {
581661 while ( true ) {
@@ -618,6 +698,33 @@ async function mainMenu() {
618698// 프로그램 시작
619699async function main ( ) {
620700 try {
701+ const mode = getArgValue ( 'mode' ) ;
702+ if ( mode ) {
703+ const xml = getArgValue ( 'xml' ) ;
704+ const query = getArgValue ( 'query' ) ;
705+ if ( mode === 'validate' ) {
706+ const filePath = xml || query ;
707+ const type = xml ? 'XML' : ( query ? 'JSON' : null ) ;
708+ await runValidateNonInteractive ( filePath , type ) ;
709+ return ;
710+ }
711+ if ( mode === 'test' ) {
712+ await runTestNonInteractive ( ) ;
713+ return ;
714+ }
715+ if ( mode === 'export' ) {
716+ const filePath = xml || query ;
717+ const type = xml ? 'XML' : ( query ? 'JSON' : null ) ;
718+ await runExportNonInteractive ( filePath , type ) ;
719+ return ;
720+ }
721+ if ( mode === 'help' ) {
722+ await runHelpNonInteractive ( ) ;
723+ return ;
724+ }
725+ process . exit ( 2 ) ;
726+ return ;
727+ }
621728 await mainMenu ( ) ;
622729 } catch ( error ) {
623730 console . error ( colors . red + `\n ${ msg . error } ${ error . message } ` + colors . reset ) ;
0 commit comments