refactor: extract model flag and simplify config return type
This commit is contained in:
parent
6dc55bc3f3
commit
d327ed614a
2 changed files with 9 additions and 8 deletions
11
index.ts
11
index.ts
|
|
@ -31,14 +31,17 @@ async function main() {
|
||||||
const newConvo = args.new ?? args.n;
|
const newConvo = args.new ?? args.n;
|
||||||
const plainOut = args.plainOut ?? args.plain ?? !process.stdout.isTTY;
|
const plainOut = args.plainOut ?? args.plain ?? !process.stdout.isTTY;
|
||||||
const plainErr = args.plainErr ?? args.plain ?? !process.stderr.isTTY;
|
const plainErr = args.plainErr ?? args.plain ?? !process.stderr.isTTY;
|
||||||
|
const modelFlag = args.model ?? args.m;
|
||||||
const saveConfigFlag = args.save ?? args.s;
|
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) {
|
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);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -65,7 +68,7 @@ async function main() {
|
||||||
convo = await loadConversation(config.model);
|
convo = await loadConversation(config.model);
|
||||||
|
|
||||||
if (args.model || args.m) {
|
if (args.model || args.m) {
|
||||||
convo.model = args.model ?? args.m ?? config.model;
|
convo.model = modelFlag ?? config.model;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,16 +8,14 @@ export interface AppConfig {
|
||||||
model?: string;
|
model?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function loadConfig(): Promise<{
|
export async function loadConfig(): Promise<AppConfig> {
|
||||||
config: AppConfig;
|
|
||||||
}> {
|
|
||||||
let config: AppConfig;
|
let config: AppConfig;
|
||||||
try {
|
try {
|
||||||
config = await configFile.json();
|
config = await configFile.json();
|
||||||
} catch {
|
} catch {
|
||||||
config = {};
|
config = {};
|
||||||
}
|
}
|
||||||
return { config };
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function saveConfig(config: AppConfig): Promise<void> {
|
export async function saveConfig(config: AppConfig): Promise<void> {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue