Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,13 @@ git-commit-ai config --set backend=llamacpp
git-commit-ai config --set model=gpt-4o
git-commit-ai config --set temperature=0.5

# List valid config keys
# Use short aliases
git-commit-ai config --set lang=pt # → default_language
git-commit-ai config --set scope=api # → default_scope
git-commit-ai config --set type=feat # → default_type
git-commit-ai config --set temp=0.5 # → temperature

# List valid config keys and aliases
git-commit-ai config --list-keys

# Create/edit config file manually
Expand Down
15 changes: 13 additions & 2 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import chalk from "chalk";
import ora from "ora";
import { createInterface } from "node:readline";

import { loadConfig, saveConfig, showConfig, getConfigPath, updateConfig, VALID_CONFIG_KEYS } from "./config.js";
import { loadConfig, saveConfig, showConfig, getConfigPath, updateConfig, VALID_CONFIG_KEYS, CONFIG_ALIASES } from "./config.js";
import {
createBackend,
detectBackend,
Expand Down Expand Up @@ -547,7 +547,18 @@ export function createProgram(): Command {
if (options.listKeys) {
console.log(chalk.bold("Valid config keys:"));
for (const key of VALID_CONFIG_KEYS) {
console.log(` ${key}`);
// Find alias for this key
const alias = Object.entries(CONFIG_ALIASES).find(([, v]) => v === key)?.[0];
if (alias) {
console.log(` ${key} ${chalk.dim(`(alias: ${alias})`)}`);
} else {
console.log(` ${key}`);
}
}
console.log();
console.log(chalk.bold("Short aliases:"));
for (const [alias, fullKey] of Object.entries(CONFIG_ALIASES)) {
console.log(` ${alias} → ${fullKey}`);
}
return;
}
Expand Down
35 changes: 29 additions & 6 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ export const VALID_CONFIG_KEYS = [

export type ConfigKey = typeof VALID_CONFIG_KEYS[number];

/**
* Short aliases for config keys
*/
export const CONFIG_ALIASES: Record<string, ConfigKey> = {
lang: "default_language",
scope: "default_scope",
type: "default_type",
url: "ollama_url",
temp: "temperature",
};

export function getConfigPath(): string {
return join(homedir(), ".config", "git-commit-ai", "config.toml");
}
Expand Down Expand Up @@ -154,24 +165,33 @@ export function showConfig(config: Config): string {
* Returns an object with success status and message
*/
export function updateConfig(key: string, value: string): { success: boolean; message: string } {
// Resolve alias to full key name
const resolvedKey = CONFIG_ALIASES[key] || key;

// Validate key
if (!VALID_CONFIG_KEYS.includes(key as ConfigKey)) {
if (!VALID_CONFIG_KEYS.includes(resolvedKey as ConfigKey)) {
const aliasHelp = Object.entries(CONFIG_ALIASES)
.map(([alias, full]) => `${alias} → ${full}`)
.join(", ");
return {
success: false,
message: `Invalid config key: "${key}". Valid keys: ${VALID_CONFIG_KEYS.join(", ")}`,
message: `Invalid config key: "${key}". Valid keys: ${VALID_CONFIG_KEYS.join(", ")}. Aliases: ${aliasHelp}`,
};
}

// Use resolved key from here
const configKey = resolvedKey as ConfigKey;

// Validate backend value
if (key === "backend" && !VALID_BACKENDS.includes(value as BackendType)) {
if (configKey === "backend" && !VALID_BACKENDS.includes(value as BackendType)) {
return {
success: false,
message: `Invalid backend: "${value}". Valid backends: ${VALID_BACKENDS.join(", ")}`,
};
}

// Validate temperature value
if (key === "temperature") {
if (configKey === "temperature") {
const temp = parseFloat(value);
if (isNaN(temp) || temp < 0 || temp > 1) {
return {
Expand All @@ -184,7 +204,7 @@ export function updateConfig(key: string, value: string): { success: boolean; me
// Load current config and update
const config = loadConfig();

switch (key) {
switch (configKey) {
case "backend":
config.backend = value as BackendType;
break;
Expand Down Expand Up @@ -212,8 +232,11 @@ export function updateConfig(key: string, value: string): { success: boolean; me
}

saveConfig(config);

// Show alias resolution in message if applicable
const keyDisplay = key !== configKey ? `${key} (${configKey})` : configKey;
return {
success: true,
message: `Config updated: ${key} = "${value}"`,
message: `Config updated: ${keyDisplay} = "${value}"`,
};
}