feat: add --version/-v flag. Closes #88

This commit is contained in:
Claude 2026-02-13 19:18:45 -05:00 committed by Tobi Lütke
parent 5dec3ab662
commit da79e77d34
No known key found for this signature in database

View File

@ -2030,6 +2030,7 @@ function parseCLI() {
type: "boolean",
},
help: { type: "boolean", short: "h" },
version: { type: "boolean", short: "v" },
// Search options
n: { type: "string" },
"min-score": { type: "string" },
@ -2155,10 +2156,32 @@ function showHelp(): void {
console.log(`Index: ${getDbPath()}`);
}
async function showVersion(): Promise<void> {
const scriptDir = import.meta.dir;
const pkgPath = resolve(scriptDir, "..", "package.json");
const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
let commit = "";
try {
const result = await $`git -C ${scriptDir} rev-parse --short HEAD`.quiet();
commit = result.text().trim();
} catch {
// Not a git repo or git not available
}
const versionStr = commit ? `${pkg.version} (${commit})` : pkg.version;
console.log(`qmd ${versionStr}`);
}
// Main CLI - only run if this is the main module
if (import.meta.main) {
const cli = parseCLI();
if (cli.values.version) {
await showVersion();
process.exit(0);
}
if (!cli.command || cli.values.help) {
showHelp();
process.exit(cli.values.help ? 0 : 1);