Skip to content

Commit 0b7d845

Browse files
committed
Added non-interactive CLI function
1 parent 6819e9d commit 0b7d845

File tree

8 files changed

+266
-1
lines changed

8 files changed

+266
-1
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
# SQL2Excel Version History
22

3+
## v1.2.10 - Non-interactive CLI & Docs (2025-10-29)
4+
5+
### ✨ New Features
6+
7+
#### Non-interactive CLI (app.js)
8+
- Added direct execution without interactive menu using `--mode`
9+
- Modes: `validate`, `test`, `export`, `help`
10+
- Works in Node and packaged EXE
11+
12+
### 📝 Documentation
13+
- README.md / README_KR.md: Added "Non-interactive CLI" usage and examples
14+
- Updated highlights to v1.2.10
15+
316
## v1.2.9 - Global Timezone System & Local Time Support (2025-10-21)
417

518
### ✨ New Features

CHANGELOG_KR.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
# SQL2Excel 버전 히스토리
22

3+
## v1.2.10 - 비대화식 CLI 및 문서 업데이트 (2025-10-29)
4+
5+
### ✨ 새로운 기능
6+
7+
#### 비대화식 CLI (app.js)
8+
- `--mode` 플래그로 대화형 메뉴 없이 직접 실행 가능
9+
- 모드: `validate`, `test`, `export`, `help`
10+
- Node 환경과 패키지 EXE 모두 지원
11+
12+
### 📝 문서
13+
- README.md / README_KR.md: "비대화식 CLI" 사용법과 예시 추가
14+
- 하이라이트를 v1.3.0으로 업데이트
15+
316
## v1.2.9 - 글로벌 타임존 시스템 및 로컬 시간 지원 (2025-10-21)
417

518
### ✨ 새로운 기능

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,41 @@ A Node.js-based tool for generating Excel files from SQL query results.
2525
- 📋 **SQL Query Formatting**: Preserve original SQL formatting with line breaks in Table of Contents
2626
- 🔧 **Input Validation**: Automatic whitespace trimming for file path inputs
2727

28+
## v1.2.10 Highlights
29+
30+
- **Non-interactive CLI**: Run tasks directly with `app.js --mode` (no menu)
31+
- Modes: `validate`, `test`, `export`, `help`
32+
- Works in both Node and packaged EXE
33+
34+
### Non-interactive CLI (New)
35+
36+
#### Node.js
37+
```bash
38+
# Validate query definition
39+
node app.js --mode=validate --xml=./queries/sample-queries.xml
40+
# or JSON
41+
node app.js --mode=validate --query=./queries/sample-queries.json
42+
43+
# Test DB connections
44+
node app.js --mode=test
45+
46+
# Export Excel
47+
node app.js --mode=export --xml=./queries/sample-queries.xml
48+
# or JSON
49+
node app.js --mode=export --query=./queries/sample-queries.json
50+
51+
# Help
52+
node app.js --mode=help
53+
```
54+
55+
#### Standalone EXE
56+
```bash
57+
sql2excel.exe --mode=validate --xml=./queries/sample-queries.xml
58+
sql2excel.exe --mode=test
59+
sql2excel.exe --mode=export --xml=./queries/sample-queries.xml
60+
sql2excel.exe --mode=help
61+
```
62+
2863
## 🚀 Quick Start
2964

3065
## 🛠️ Installation and Setup

README_KR.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,41 @@ SQL 쿼리 결과를 엑셀 파일로 생성하는 Node.js 기반 도구입니
2525
- 📋 **SQL 쿼리 포맷팅**: 목차에서 줄바꿈을 포함한 원본 SQL 포맷 유지
2626
- 🔧 **입력 유효성 검증**: 파일 경로 입력에 대한 자동 공백 제거
2727

28+
## v1.2.10 하이라이트
29+
30+
- **비대화식 CLI**: 메뉴 없이 `app.js --mode`로 직접 실행
31+
- 모드: `validate`, `test`, `export`, `help`
32+
- Node 실행 및 배포 EXE 모두 지원
33+
34+
### 비대화형 CLI (신규)
35+
36+
#### Node.js
37+
```bash
38+
# 쿼리정의 검증
39+
node app.js --mode=validate --xml=./queries/sample-queries.xml
40+
# 또는 JSON
41+
node app.js --mode=validate --query=./queries/sample-queries.json
42+
43+
# DB 연결 테스트
44+
node app.js --mode=test
45+
46+
# 엑셀 생성
47+
node app.js --mode=export --xml=./queries/sample-queries.xml
48+
# 또는 JSON
49+
node app.js --mode=export --query=./queries/sample-queries.json
50+
51+
# 도움말
52+
node app.js --mode=help
53+
```
54+
55+
#### 독립 실행 파일(EXE)
56+
```bash
57+
sql2excel.exe --mode=validate --xml=./queries/sample-queries.xml
58+
sql2excel.exe --mode=test
59+
sql2excel.exe --mode=export --xml=./queries/sample-queries.xml
60+
sql2excel.exe --mode=help
61+
```
62+
2863
## 🚀 빠른 시작
2964

3065
## 🛠️ 설치 및 설정

USER_MANUAL.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,37 @@ node src/excel-cli.js list-styles
229229
sql2excel.exe list-styles
230230
```
231231

232+
## Non-interactive CLI (New in v1.2.10)
233+
234+
Run tasks directly without the interactive menu using `--mode`.
235+
236+
### Node.js
237+
```bash
238+
# Validate query definition
239+
node app.js --mode=validate --xml=./queries/sample-queries.xml
240+
# or JSON
241+
node app.js --mode=validate --query=./queries/sample-queries.json
242+
243+
# Test DB connections
244+
node app.js --mode=test
245+
246+
# Export Excel
247+
node app.js --mode=export --xml=./queries/sample-queries.xml
248+
# or JSON
249+
node app.js --mode=export --query=./queries/sample-queries.json
250+
251+
# Help
252+
node app.js --mode=help
253+
```
254+
255+
### Standalone EXE
256+
```bash
257+
sql2excel.exe --mode=validate --xml=./queries/sample-queries.xml
258+
sql2excel.exe --mode=test
259+
sql2excel.exe --mode=export --xml=./queries/sample-queries.xml
260+
sql2excel.exe --mode=help
261+
```
262+
232263
## 📋 Query Definition File Structure
233264

234265
### XML Format

USER_MANUAL_KR.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,37 @@ node src/excel-cli.js list-styles
229229
sql2excel.exe list-styles
230230
```
231231

232+
## 비대화형 CLI (v1.2.10 신규)
233+
234+
`--mode` 플래그를 사용해 대화형 메뉴 없이 바로 실행할 수 있습니다.
235+
236+
### Node.js
237+
```bash
238+
# 쿼리 정의 검증
239+
node app.js --mode=validate --xml=./queries/sample-queries.xml
240+
# 또는 JSON
241+
node app.js --mode=validate --query=./queries/sample-queries.json
242+
243+
# DB 연결 테스트
244+
node app.js --mode=test
245+
246+
# 엑셀 내보내기
247+
node app.js --mode=export --xml=./queries/sample-queries.xml
248+
# 또는 JSON
249+
node app.js --mode=export --query=./queries/sample-queries.json
250+
251+
# 도움말
252+
node app.js --mode=help
253+
```
254+
255+
### 독립 실행 파일(EXE)
256+
```bash
257+
sql2excel.exe --mode=validate --xml=./queries/sample-queries.xml
258+
sql2excel.exe --mode=test
259+
sql2excel.exe --mode=export --xml=./queries/sample-queries.xml
260+
sql2excel.exe --mode=help
261+
```
262+
232263
## 📋 쿼리 정의 파일 구조
233264

234265
### XML 형식

app.js

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
// 메인 메뉴
580660
async function mainMenu() {
581661
while (true) {
@@ -618,6 +698,33 @@ async function mainMenu() {
618698
// 프로그램 시작
619699
async 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);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sql2excel",
3-
"version": "1.2.9",
3+
"version": "1.2.10",
44
"description": "SQL 쿼리 결과를 엑셀 파일로 저장하는 도구 (시트별 쿼리, 변수, XML/JSON 지원)",
55
"main": "app.js",
66
"scripts": {

0 commit comments

Comments
 (0)