itamatrix 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +20 -2
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { realpathSync } from "node:fs";
|
|
2
4
|
import { pathToFileURL } from "node:url";
|
|
3
5
|
import { Command, InvalidArgumentError } from "commander";
|
|
4
6
|
import { runSearchCommand, } from "./commands/search.js";
|
|
@@ -35,11 +37,14 @@ function resolveFormat(json, table) {
|
|
|
35
37
|
// Auto-detect: TTY → table, piped → json.
|
|
36
38
|
return process.stdout.isTTY ? "table" : "json";
|
|
37
39
|
}
|
|
40
|
+
// Read version from package.json so it tracks semantic-release bumps (which only
|
|
41
|
+
// update package.json, never this file). dist/cli.js sits one dir below package root.
|
|
42
|
+
const { version } = createRequire(import.meta.url)("../package.json");
|
|
38
43
|
export const program = new Command();
|
|
39
44
|
program
|
|
40
45
|
.name("itamatrix")
|
|
41
46
|
.description("CLI for ITA Matrix flight search")
|
|
42
|
-
.version(
|
|
47
|
+
.version(version)
|
|
43
48
|
.option("--json", "force JSON output")
|
|
44
49
|
.option("--table", "force table output")
|
|
45
50
|
.option("--no-cache", "bypass the result cache (always query live)")
|
|
@@ -148,6 +153,19 @@ program
|
|
|
148
153
|
});
|
|
149
154
|
// Parse only when run as the CLI entrypoint, so tools can import `program` to
|
|
150
155
|
// introspect commands/options (see scripts/gen-skill.ts) without triggering a run.
|
|
151
|
-
|
|
156
|
+
// argv[1] is realpath'd because npm/npx invoke the bin via a symlink, whose path
|
|
157
|
+
// would otherwise never match this module's resolved import.meta.url.
|
|
158
|
+
function isCliEntrypoint() {
|
|
159
|
+
const entry = process.argv[1];
|
|
160
|
+
if (!entry)
|
|
161
|
+
return false;
|
|
162
|
+
try {
|
|
163
|
+
return import.meta.url === pathToFileURL(realpathSync(entry)).href;
|
|
164
|
+
}
|
|
165
|
+
catch {
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
if (isCliEntrypoint()) {
|
|
152
170
|
program.parseAsync(process.argv);
|
|
153
171
|
}
|