Skip to content

Commit

Permalink
gussy up status
Browse files Browse the repository at this point in the history
  • Loading branch information
henryfauna committed Dec 12, 2024
1 parent 45ddf9c commit d0d9f20
Showing 1 changed file with 54 additions and 13 deletions.
67 changes: 54 additions & 13 deletions src/commands/schema/status.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Check warning on line 19 in src/commands/schema/status.mjs

View workflow job for this annotation

GitHub Actions / lint

Async function 'doStatus' has a complexity of 19. Maximum allowed is 10
const logger = container.resolve("logger");
const makeFaunaRequest = container.resolve("makeFaunaRequest");
Expand Down Expand Up @@ -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;
}
Expand All @@ -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) {
Expand Down

0 comments on commit d0d9f20

Please sign in to comment.