From d0d9f2077418789513ca5f98795b3780c4afe3af Mon Sep 17 00:00:00 2001 From: Henry Ball Date: Thu, 12 Dec 2024 13:21:01 -0800 Subject: [PATCH] gussy up status --- src/commands/schema/status.mjs | 67 +++++++++++++++++++++++++++------- 1 file changed, 54 insertions(+), 13 deletions(-) diff --git a/src/commands/schema/status.mjs b/src/commands/schema/status.mjs index 48fa1dfb..09331bf8 100644 --- a/src/commands/schema/status.mjs +++ b/src/commands/schema/status.mjs @@ -10,6 +10,12 @@ import { getSecret } from "../../lib/fauna-client.mjs"; import { reformatFSL } from "../../lib/schema.mjs"; import { localSchemaOptions } from "./schema.mjs"; +const tab = " "; +const logLineWithTab = ( + line, + { numTabs = 1, logger = container.resolve("logger").stdout } = {}, +) => logger(tab.repeat(numTabs) + line); + async function doStatus(argv) { const logger = container.resolve("logger"); const makeFaunaRequest = container.resolve("makeFaunaRequest"); @@ -48,19 +54,47 @@ async function doStatus(argv) { } // Output the status response - logger.stdout(`Staged changes: ${chalk.bold(statusResponse.status)}`); - if (statusResponse.pending_summary !== "") { - logger.stdout(statusResponse.pending_summary); - } - if (statusResponse.diff) { - logger.stdout("Staged changes:\n"); - logger.stdout(statusResponse.diff.split("\n").join("\n ")); + + switch (statusResponse.status) { + case "none": + logger.stdout( + `No changes staged ${argv.database ? `for '${chalk.bold(argv.database)}'` : ""}.`, + ); + break; + case "pending": + logger.stdout( + `Staged changes ${argv.database ? `for '${chalk.bold(argv.database)}'` : ""} are ${chalk.bold(statusResponse.status)}:`, + ); + if (statusResponse.pending_summary) { + logLineWithTab(statusResponse.pending_summary.trim()); + } + break; + case "ready": + logger.stdout( + `Staged changes ${argv.database ? `for '${chalk.bold(argv.database)}'` : ""} are ${chalk.bold(statusResponse.status)}:`, + ); + if (statusResponse.diff) { + logLineWithTab("(use `fauna schema commit` to commit staged changes)"); + for (const line of statusResponse.diff.trim().split("\n")) { + logLineWithTab(line, { numTabs: 3 }); + } + } + break; + case "failed": + logger.stdout( + `Staged changes ${argv.database ? `for '${chalk.bold(argv.database)}'` : ""} have ${chalk.bold(statusResponse.status)}. `, + ); + break; + default: + logLineWithTab(`Staged changes: ${statusResponse.status}`); + break; } // Output the diff response + if (!hasLocalSchema) { logger.stdout( - `Local changes: ${chalk.bold(`no schema files found in '${absoluteDirPath}'`)}\n`, + `\nNo local changes. No schema files found in '${chalk.bold(absoluteDirPath)}'.\n`, ); return; } @@ -70,14 +104,21 @@ async function doStatus(argv) { } if (diffResponse.diff === "") { - logger.stdout(`Local changes: ${chalk.bold("none")}\n`); + logger.stdout( + `\nNo local changes${argv.dir !== "." ? ` in '${chalk.bold(argv.dir)}'` : ""}.\n`, + ); return; } - logger.stdout(`Local changes:\n`); - logger.stdout(` ${diffResponse.diff.split("\n").join("\n ")}`); - logger.stdout("(use `fauna schema diff` to display local changes)"); - logger.stdout("(use `fauna schema push` to stage local changes)"); + logger.stdout( + `\nLocal changes${argv.dir !== "." ? ` in '${chalk.bold(argv.dir)}'` : ""}:`, + ); + logLineWithTab("(use `fauna schema diff` to display local changes)"); + logLineWithTab("(use `fauna schema push` to stage local changes)"); + for (const line of diffResponse.diff.trim().split("\n")) { + logLineWithTab(line, { numTabs: 3 }); + } + logger.stdout(""); } function buildStatusCommand(yargs) {