refactor: extract model flag and simplify config return type

This commit is contained in:
mitchell 2026-04-18 19:10:07 -04:00
parent 6dc55bc3f3
commit d327ed614a
2 changed files with 9 additions and 8 deletions

View file

@ -31,14 +31,17 @@ async function main() {
const newConvo = args.new ?? args.n;
const plainOut = args.plainOut ?? args.plain ?? !process.stdout.isTTY;
const plainErr = args.plainErr ?? args.plain ?? !process.stderr.isTTY;
const modelFlag = args.model ?? args.m;
const saveConfigFlag = args.save ?? args.s;
const { config } = await loadConfig();
const config = await loadConfig();
config.model = args.model ?? args.m ?? config.model;
config.model = modelFlag ?? config.model;
if (!config.model) {
console.error("Please specify a model with --model/-m at least one time.");
console.error(
"Please run 'aicl --model <model> --save' to set a default model.",
);
process.exit(1);
}
@ -65,7 +68,7 @@ async function main() {
convo = await loadConversation(config.model);
if (args.model || args.m) {
convo.model = args.model ?? args.m ?? config.model;
convo.model = modelFlag ?? config.model;
}
}

View file

@ -8,16 +8,14 @@ export interface AppConfig {
model?: string;
}
export async function loadConfig(): Promise<{
config: AppConfig;
}> {
export async function loadConfig(): Promise<AppConfig> {
let config: AppConfig;
try {
config = await configFile.json();
} catch {
config = {};
}
return { config };
return config;
}
export async function saveConfig(config: AppConfig): Promise<void> {