summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYurenHao0426 <blackhao0426@gmail.com>2026-09-13 04:09:27 +0000
committerYurenHao0426 <blackhao0426@gmail.com>2026-09-13 04:09:27 +0000
commitc14704c46a47418e77d6f1ad76f6c204b15c056b (patch)
tree4c1285cc6ae15f57452533bdd2346ebff2d0d3a4
parentc78a5ef589cacb5d7bdc7586b0cc270aded4b5fc (diff)
CLI: fix duplicate shebang in bundle; accept flags before the command (--help, -h)
esbuild already keeps the shebang from src/cli/main.ts, so the extra banner produced two shebang lines and node refused to load the bundle. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
-rw-r--r--package.json2
-rw-r--r--src/cli/args.ts12
2 files changed, 10 insertions, 4 deletions
diff --git a/package.json b/package.json
index d736062..d187d6a 100644
--- a/package.json
+++ b/package.json
@@ -8,7 +8,7 @@
"scripts": {
"dev": "electron-vite dev",
"build": "electron-vite build && npx esbuild src/mcp/lattex.mjs --bundle --platform=node --format=esm --outfile=out/mcp/lattex.mjs",
- "build:cli": "npx esbuild src/cli/main.ts --bundle --platform=node --format=esm --target=node18 --outfile=out/cli/lattex-cli.mjs --external:ws --banner:js='#!/usr/bin/env node'",
+ "build:cli": "npx esbuild src/cli/main.ts --bundle --platform=node --format=esm --target=node18 --outfile=out/cli/lattex-cli.mjs --external:ws",
"typecheck:cli": "npx tsc --project tsconfig.cli.json --noEmit",
"test:cli": "node --experimental-vm-modules out/cli/test.mjs",
"preview": "electron-vite preview",
diff --git a/src/cli/args.ts b/src/cli/args.ts
index 0f7a767..25d3216 100644
--- a/src/cli/args.ts
+++ b/src/cli/args.ts
@@ -8,13 +8,17 @@ export interface ParsedArgs {
export function parseArgs(argv: string[]): ParsedArgs {
const args = argv.slice(2)
- const command = args[0] || ''
+ let command = ''
const positional: string[] = []
const flags: Record<string, string | boolean> = {}
- for (let i = 1; i < args.length; i++) {
+ // The command is the first non-flag token, so `lattex-cli --help` and
+ // `lattex-cli --json projects` both work.
+ for (let i = 0; i < args.length; i++) {
const arg = args[i]
- if (arg.startsWith('--')) {
+ if (arg === '-h') {
+ flags.help = true
+ } else if (arg.startsWith('--')) {
const eqIdx = arg.indexOf('=')
if (eqIdx !== -1) {
flags[arg.slice(2, eqIdx)] = arg.slice(eqIdx + 1)
@@ -30,6 +34,8 @@ export function parseArgs(argv: string[]): ParsedArgs {
} else {
flags[arg.slice(2)] = true
}
+ } else if (!command) {
+ command = arg
} else {
positional.push(arg)
}