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.
This commit is contained in:
Matthías Páll Gissurarson 2026-02-01 22:36:51 +01:00 committed by GitHub
parent 102ff861d3
commit 5de063ae96
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 1 deletions

View File

@ -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`);
}
/**

View File

@ -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