fix: improve config loading flow and table column width
This commit is contained in:
parent
decfd2bde0
commit
7f0498fc84
3 changed files with 18 additions and 11 deletions
|
|
@ -10,13 +10,14 @@ export interface AppConfig {
|
|||
model: string;
|
||||
}
|
||||
|
||||
export async function initConfig(old?: AppConfig): Promise<AppConfig> {
|
||||
export async function initConfig(old: AppConfig | null): Promise<AppConfig> {
|
||||
console.log();
|
||||
intro(chalk.blue("Welcome to LMC. Let's make a new config!"));
|
||||
|
||||
const baseURL = await text({
|
||||
message: "What's your base URL:",
|
||||
initialValue: old?.baseURL,
|
||||
defaultValue: "http://127.0.0.1:8080/v1",
|
||||
placeholder: "http://127.0.0.1:8080/v1",
|
||||
defaultValue: old?.baseURL ?? "http://127.0.0.1:8080/v1",
|
||||
placeholder: old?.baseURL ?? "http://127.0.0.1:8080/v1",
|
||||
});
|
||||
if (isCancel(baseURL)) process.exit(1);
|
||||
|
||||
|
|
@ -32,6 +33,7 @@ export async function initConfig(old?: AppConfig): Promise<AppConfig> {
|
|||
const config = { baseURL, model } satisfies AppConfig;
|
||||
|
||||
await configFile.write(JSON.stringify(config, null, " "));
|
||||
|
||||
outro(chalk.green("Configuration saved!"));
|
||||
|
||||
return config;
|
||||
|
|
@ -52,12 +54,17 @@ async function getModels(url: string) {
|
|||
return models.data.map((model) => ({ value: model.id }));
|
||||
}
|
||||
|
||||
export async function loadConfig(): Promise<AppConfig> {
|
||||
export async function loadConfig(
|
||||
configFlag: boolean | undefined,
|
||||
): Promise<AppConfig | null> {
|
||||
let config: AppConfig;
|
||||
try {
|
||||
config = await configFile.json();
|
||||
} catch {
|
||||
config = await initConfig();
|
||||
if (configFlag) return null;
|
||||
console.error(`Config not found at ${configFile.name}`);
|
||||
return null;
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -110,7 +110,7 @@ export async function renderMarkdown(
|
|||
.header(header)
|
||||
.body(body)
|
||||
.border()
|
||||
.maxColWidth(Math.floor(columns / header.length) - 3)
|
||||
.maxColWidth(Math.floor(columns / header.length) - header.length)
|
||||
.toString();
|
||||
header = [];
|
||||
body = [];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue