Skip to content

Commit 5e37b83

Browse files
authored
Merge pull request #8 from vavasilva/feat/config-aliases
feat: add short aliases for config keys
2 parents 883c9b4 + 80c1c74 commit 5e37b83

File tree

3 files changed

+49
-9
lines changed

3 files changed

+49
-9
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,13 @@ git-commit-ai config --set backend=llamacpp
338338
git-commit-ai config --set model=gpt-4o
339339
git-commit-ai config --set temperature=0.5
340340

341-
# List valid config keys
341+
# Use short aliases
342+
git-commit-ai config --set lang=pt # → default_language
343+
git-commit-ai config --set scope=api # → default_scope
344+
git-commit-ai config --set type=feat # → default_type
345+
git-commit-ai config --set temp=0.5 # → temperature
346+
347+
# List valid config keys and aliases
342348
git-commit-ai config --list-keys
343349

344350
# Create/edit config file manually

src/cli.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import chalk from "chalk";
33
import ora from "ora";
44
import { createInterface } from "node:readline";
55

6-
import { loadConfig, saveConfig, showConfig, getConfigPath, updateConfig, VALID_CONFIG_KEYS } from "./config.js";
6+
import { loadConfig, saveConfig, showConfig, getConfigPath, updateConfig, VALID_CONFIG_KEYS, CONFIG_ALIASES } from "./config.js";
77
import {
88
createBackend,
99
detectBackend,
@@ -547,7 +547,18 @@ export function createProgram(): Command {
547547
if (options.listKeys) {
548548
console.log(chalk.bold("Valid config keys:"));
549549
for (const key of VALID_CONFIG_KEYS) {
550-
console.log(` ${key}`);
550+
// Find alias for this key
551+
const alias = Object.entries(CONFIG_ALIASES).find(([, v]) => v === key)?.[0];
552+
if (alias) {
553+
console.log(` ${key} ${chalk.dim(`(alias: ${alias})`)}`);
554+
} else {
555+
console.log(` ${key}`);
556+
}
557+
}
558+
console.log();
559+
console.log(chalk.bold("Short aliases:"));
560+
for (const [alias, fullKey] of Object.entries(CONFIG_ALIASES)) {
561+
console.log(` ${alias}${fullKey}`);
551562
}
552563
return;
553564
}

src/config.ts

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,17 @@ export const VALID_CONFIG_KEYS = [
3333

3434
export type ConfigKey = typeof VALID_CONFIG_KEYS[number];
3535

36+
/**
37+
* Short aliases for config keys
38+
*/
39+
export const CONFIG_ALIASES: Record<string, ConfigKey> = {
40+
lang: "default_language",
41+
scope: "default_scope",
42+
type: "default_type",
43+
url: "ollama_url",
44+
temp: "temperature",
45+
};
46+
3647
export function getConfigPath(): string {
3748
return join(homedir(), ".config", "git-commit-ai", "config.toml");
3849
}
@@ -154,24 +165,33 @@ export function showConfig(config: Config): string {
154165
* Returns an object with success status and message
155166
*/
156167
export function updateConfig(key: string, value: string): { success: boolean; message: string } {
168+
// Resolve alias to full key name
169+
const resolvedKey = CONFIG_ALIASES[key] || key;
170+
157171
// Validate key
158-
if (!VALID_CONFIG_KEYS.includes(key as ConfigKey)) {
172+
if (!VALID_CONFIG_KEYS.includes(resolvedKey as ConfigKey)) {
173+
const aliasHelp = Object.entries(CONFIG_ALIASES)
174+
.map(([alias, full]) => `${alias}${full}`)
175+
.join(", ");
159176
return {
160177
success: false,
161-
message: `Invalid config key: "${key}". Valid keys: ${VALID_CONFIG_KEYS.join(", ")}`,
178+
message: `Invalid config key: "${key}". Valid keys: ${VALID_CONFIG_KEYS.join(", ")}. Aliases: ${aliasHelp}`,
162179
};
163180
}
181+
182+
// Use resolved key from here
183+
const configKey = resolvedKey as ConfigKey;
164184

165185
// Validate backend value
166-
if (key === "backend" && !VALID_BACKENDS.includes(value as BackendType)) {
186+
if (configKey === "backend" && !VALID_BACKENDS.includes(value as BackendType)) {
167187
return {
168188
success: false,
169189
message: `Invalid backend: "${value}". Valid backends: ${VALID_BACKENDS.join(", ")}`,
170190
};
171191
}
172192

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

187-
switch (key) {
207+
switch (configKey) {
188208
case "backend":
189209
config.backend = value as BackendType;
190210
break;
@@ -212,8 +232,11 @@ export function updateConfig(key: string, value: string): { success: boolean; me
212232
}
213233

214234
saveConfig(config);
235+
236+
// Show alias resolution in message if applicable
237+
const keyDisplay = key !== configKey ? `${key} (${configKey})` : configKey;
215238
return {
216239
success: true,
217-
message: `Config updated: ${key} = "${value}"`,
240+
message: `Config updated: ${keyDisplay} = "${value}"`,
218241
};
219242
}

0 commit comments

Comments
 (0)