From 423d3198ee92c9946439fb0afe0729e61232d0f1 Mon Sep 17 00:00:00 2001 From: Amolith Date: Sun, 8 Feb 2026 00:33:17 +0000 Subject: [PATCH] feat: add version flag Add -v/--version flag support to CLI. Also fix dist/ entry point in package.json. --- package.json | 2 +- src/cli/index.ts | 22 +++++++++++++++++++++- src/cli/parse-args.ts | 2 ++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 0e88cb4cc55c7507d3e562fdb7f1a4f52e0db221..a07e22033b7c4c9f26371eefb8f5a1b62d9104ad 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "private": true, "type": "module", "bin": { - "rumilo": "./dist/cli/index.js" + "rumilo": "./dist/index.js" }, "scripts": { "dev": "bun src/cli/index.ts", diff --git a/src/cli/index.ts b/src/cli/index.ts index 378f0a2d722aa8a3ef7cd6bd096ce48e584f4b01..1c177b2854c7c22f1ab67c7db5fbc12ac541d9fd 100755 --- a/src/cli/index.ts +++ b/src/cli/index.ts @@ -3,11 +3,31 @@ import { runWebCommand } from "./commands/web.js"; import { runRepoCommand } from "./commands/repo.js"; import { RumiloError } from "../util/errors.js"; import { parseArgs } from "./parse-args.js"; +import { readFileSync } from "node:fs"; +import { join } from "node:path"; +import { fileURLToPath } from "node:url"; + +const VERSION = "0.1.0"; async function main() { const { command, options, positional } = parseArgs(process.argv); - if (!command || command === "help") { + // Handle version flag coming before any command (e.g., rumilo -v) + // When short flags come right after process.argv, they end up in 'command' + if (command && (command === "-v" || command === "--version") && Object.keys(options).length === 0 && positional.length === 0) { + console.log(`rumilo v${VERSION}`); + process.exit(0); + } + + const actualCommand = command?.startsWith("-") ? undefined : command; + + // Handle version/short version as flag (before command) or as command + if (options.version || actualCommand === "version" || actualCommand === "v") { + console.log(`rumilo v${VERSION}`); + process.exit(0); + } + + if (!actualCommand || actualCommand === "help" || actualCommand === "--help" || actualCommand === "-h" || options.help) { console.log("rumilo web [-u URL] [--model ] [--verbose] [--no-cleanup]"); console.log("rumilo repo -u [--ref ] [--full] [--model ] [--verbose] [--no-cleanup]"); process.exit(0); diff --git a/src/cli/parse-args.ts b/src/cli/parse-args.ts index 76eb674276605123caaeb4ec3b9cbec0b67a837b..8c11ed2a33cf5efd3ed56f1f87d1fc1b490fef73 100644 --- a/src/cli/parse-args.ts +++ b/src/cli/parse-args.ts @@ -42,6 +42,8 @@ export function parseArgs(args: string[]): ParsedArgs { // else: -u with no value — uri stays unset, command handler validates } else if (short === "f") { options["full"] = true; + } else if (short === "v") { + options["version"] = true; } else { options[short] = true; }