style: colorize providers list

This commit is contained in:
Peter Steinberger
2026-01-08 02:59:12 +01:00
parent 440a5b82cf
commit 6f82ec7b83

View File

@@ -130,17 +130,32 @@ function formatAccountLabel(params: { accountId: string; name?: string }) {
return base; return base;
} }
const colorValue = (value: string) => {
if (value === "none") return chalk.red(value);
if (value === "env") return chalk.cyan(value);
return chalk.green(value);
};
function formatEnabled(value: boolean | undefined): string { function formatEnabled(value: boolean | undefined): string {
return value === false ? "disabled" : "enabled"; return value === false ? chalk.red("disabled") : chalk.green("enabled");
} }
function formatConfigured(value: boolean): string { function formatConfigured(value: boolean): string {
return value ? "configured" : "not configured"; return value ? chalk.green("configured") : chalk.yellow("not configured");
} }
function formatTokenSource(source?: string): string { function formatTokenSource(source?: string): string {
if (!source || source === "none") return "token=none"; const value = source || "none";
return `token=${source}`; return `token=${colorValue(value)}`;
}
function formatSource(label: string, source?: string): string {
const value = source || "none";
return `${label}=${colorValue(value)}`;
}
function formatLinked(value: boolean): string {
return value ? chalk.green("linked") : chalk.yellow("not linked");
} }
function applyAccountName(params: { function applyAccountName(params: {
@@ -481,17 +496,19 @@ export async function providersListCommand(
} }
const lines: string[] = []; const lines: string[] = [];
lines.push("Chat providers:"); lines.push(chalk.bold("Chat providers:"));
for (const accountId of whatsappAccounts) { for (const accountId of whatsappAccounts) {
const { authDir } = resolveWhatsAppAuthDir({ cfg, accountId }); const { authDir } = resolveWhatsAppAuthDir({ cfg, accountId });
const linked = await webAuthExists(authDir); const linked = await webAuthExists(authDir);
const name = cfg.whatsapp?.accounts?.[accountId]?.name; const name = cfg.whatsapp?.accounts?.[accountId]?.name;
lines.push( lines.push(
`- WhatsApp ${formatAccountLabel({ `- ${chalk.cyan("WhatsApp")} ${chalk.bold(
accountId, formatAccountLabel({
name, accountId,
})}: ${linked ? "linked" : "not linked"}, ${formatEnabled( name,
}),
)}: ${formatLinked(linked)}, ${formatEnabled(
cfg.whatsapp?.accounts?.[accountId]?.enabled ?? cfg.whatsapp?.accounts?.[accountId]?.enabled ??
cfg.web?.enabled ?? cfg.web?.enabled ??
true, true,
@@ -502,10 +519,12 @@ export async function providersListCommand(
for (const accountId of telegramAccounts) { for (const accountId of telegramAccounts) {
const account = resolveTelegramAccount({ cfg, accountId }); const account = resolveTelegramAccount({ cfg, accountId });
lines.push( lines.push(
`- Telegram ${formatAccountLabel({ `- ${chalk.cyan("Telegram")} ${chalk.bold(
accountId, formatAccountLabel({
name: account.name, accountId,
})}: ${formatConfigured(Boolean(account.token))}, ${formatTokenSource( name: account.name,
}),
)}: ${formatConfigured(Boolean(account.token))}, ${formatTokenSource(
account.tokenSource, account.tokenSource,
)}, ${formatEnabled(account.enabled)}`, )}, ${formatEnabled(account.enabled)}`,
); );
@@ -514,10 +533,12 @@ export async function providersListCommand(
for (const accountId of discordAccounts) { for (const accountId of discordAccounts) {
const account = resolveDiscordAccount({ cfg, accountId }); const account = resolveDiscordAccount({ cfg, accountId });
lines.push( lines.push(
`- Discord ${formatAccountLabel({ `- ${chalk.cyan("Discord")} ${chalk.bold(
accountId, formatAccountLabel({
name: account.name, accountId,
})}: ${formatConfigured(Boolean(account.token))}, ${formatTokenSource( name: account.name,
}),
)}: ${formatConfigured(Boolean(account.token))}, ${formatTokenSource(
account.tokenSource, account.tokenSource,
)}, ${formatEnabled(account.enabled)}`, )}, ${formatEnabled(account.enabled)}`,
); );
@@ -527,10 +548,15 @@ export async function providersListCommand(
const account = resolveSlackAccount({ cfg, accountId }); const account = resolveSlackAccount({ cfg, accountId });
const configured = Boolean(account.botToken && account.appToken); const configured = Boolean(account.botToken && account.appToken);
lines.push( lines.push(
`- Slack ${formatAccountLabel({ `- ${chalk.cyan("Slack")} ${chalk.bold(
accountId, formatAccountLabel({
name: account.name, accountId,
})}: ${formatConfigured(configured)}, bot=${account.botTokenSource}, app=${account.appTokenSource}, ${formatEnabled( name: account.name,
}),
)}: ${formatConfigured(configured)}, ${formatSource(
"bot",
account.botTokenSource,
)}, ${formatSource("app", account.appTokenSource)}, ${formatEnabled(
account.enabled, account.enabled,
)}`, )}`,
); );
@@ -539,33 +565,39 @@ export async function providersListCommand(
for (const accountId of signalAccounts) { for (const accountId of signalAccounts) {
const account = resolveSignalAccount({ cfg, accountId }); const account = resolveSignalAccount({ cfg, accountId });
lines.push( lines.push(
`- Signal ${formatAccountLabel({ `- ${chalk.cyan("Signal")} ${chalk.bold(
accountId, formatAccountLabel({
name: account.name, accountId,
})}: ${formatConfigured(account.configured)}, base=${account.baseUrl}, ${formatEnabled( name: account.name,
account.enabled, }),
)}`, )}: ${formatConfigured(account.configured)}, base=${chalk.dim(
account.baseUrl,
)}, ${formatEnabled(account.enabled)}`,
); );
} }
for (const accountId of imessageAccounts) { for (const accountId of imessageAccounts) {
const account = resolveIMessageAccount({ cfg, accountId }); const account = resolveIMessageAccount({ cfg, accountId });
lines.push( lines.push(
`- iMessage ${formatAccountLabel({ `- ${chalk.cyan("iMessage")} ${chalk.bold(
accountId, formatAccountLabel({
name: account.name, accountId,
})}: ${formatEnabled(account.enabled)}`, name: account.name,
}),
)}: ${formatEnabled(account.enabled)}`,
); );
} }
lines.push(""); lines.push("");
lines.push("Auth providers (OAuth + API keys):"); lines.push(chalk.bold("Auth providers (OAuth + API keys):"));
if (authProfiles.length === 0) { if (authProfiles.length === 0) {
lines.push("- none"); lines.push(chalk.dim("- none"));
} else { } else {
for (const profile of authProfiles) { for (const profile of authProfiles) {
const external = profile.isExternal ? " (synced)" : ""; const external = profile.isExternal ? chalk.dim(" (synced)") : "";
lines.push(`- ${profile.id} (${profile.type}${external})`); lines.push(
`- ${chalk.cyan(profile.id)} (${chalk.green(profile.type)}${external})`,
);
} }
} }