Forráskód Böngészése

Fix: Add missing --index option to argument parser (#84)

* 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 <name> loads ~/.config/qmd/<name>.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.
Matthías Páll Gissurarson 3 hónapja
szülő
commit
5de063ae96
2 módosított fájl, 17 hozzáadás és 1 törlés
  1. 12 1
      src/collections.ts
  2. 5 0
      src/qmd.ts

+ 12 - 1
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`);
 }
 
 /**

+ 5 - 0
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