From 5de063ae96f984906970e886bd13130eb35b46fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matth=C3=ADas=20P=C3=A1ll=20Gissurarson?= Date: Sun, 1 Feb 2026 22:36:51 +0100 Subject: [PATCH] Fix: Add missing --index option to argument parser (#84) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix: Add missing --index option to argument parser The --index flag was documented and used in code but not defined in parseArgs options, causing it to be ignored. Now properly handles custom index names like: qmd --index test status * Feature: Use index name for config files too Now --index loads ~/.config/qmd/.yml instead of index.yml. This allows completely separate indexes with their own collections. Example: qmd --index hackage status → Uses ~/.config/qmd/hackage.yml + ~/.cache/qmd/hackage.sqlite Moved hackage collection to hackage.yml for separation. --- src/collections.ts | 13 ++++++++++++- src/qmd.ts | 5 +++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/collections.ts b/src/collections.ts index 6cce4ef..f13ba70 100644 --- a/src/collections.ts +++ b/src/collections.ts @@ -50,6 +50,17 @@ export interface NamedCollection extends Collection { // Configuration paths // ============================================================================ +// Current index name (default: "index") +let currentIndexName: string = "index"; + +/** + * Set the current index name for config file lookup + * Config file will be ~/.config/qmd/{indexName}.yml + */ +export function setConfigIndexName(name: string): void { + currentIndexName = name; +} + function getConfigDir(): string { // Allow override via QMD_CONFIG_DIR for testing if (process.env.QMD_CONFIG_DIR) { @@ -59,7 +70,7 @@ function getConfigDir(): string { } function getConfigFilePath(): string { - return join(getConfigDir(), "index.yml"); + return join(getConfigDir(), `${currentIndexName}.yml`); } /** diff --git a/src/qmd.ts b/src/qmd.ts index 29fd2d1..97d1953 100755 --- a/src/qmd.ts +++ b/src/qmd.ts @@ -81,6 +81,7 @@ import { removeContext as yamlRemoveContext, setGlobalContext, listAllContexts, + setConfigIndexName, } from "./collections.js"; // Enable production mode - allows using default database path @@ -2291,6 +2292,9 @@ function parseCLI() { args: Bun.argv.slice(2), // Skip bun and script path options: { // Global options + index: { + type: "string", + }, context: { type: "string", }, @@ -2331,6 +2335,7 @@ function parseCLI() { const indexName = values.index as string | undefined; if (indexName) { setIndexName(indexName); + setConfigIndexName(indexName); } // Determine output format