Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/v3' into v3-codeowners
Browse files Browse the repository at this point in the history
  • Loading branch information
ecooper committed Nov 22, 2024
2 parents 0410a56 + 7204707 commit 68d176d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
10 changes: 10 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
### Quick Start

```
npm install
npm run build
./src/user-entrypoint.mjs
```



### Application versions

This project has 3 runnable entrypoints (a raw ESM one, a built CJS one, and an SEA one). You can read more about them [here](./sea/README.md).
Expand Down
9 changes: 6 additions & 3 deletions src/cli.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,12 @@ export async function run(argvInput, _container) {
builtYargs = buildYargs(argvInput);
await parseYargs(builtYargs);
} catch (e) {
const message = `${chalk.reset(await builtYargs.getHelp())}\n\n${chalk.red(
e.message,
)}`;
let subMessage = chalk.reset("Use 'fauna <command> --help' for more information about a command.");

if (argvInput.length > 0) {
subMessage = chalk.red(e.message);
}
const message = `${chalk.reset(await builtYargs.getHelp())}\n\n${subMessage}`;
logger.stderr(message);
logger.fatal(e.stack, "error");
const exitCode = e.exitCode !== undefined ? e.exitCode : 1;
Expand Down
18 changes: 17 additions & 1 deletion test/general-cli.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe("cli operations", function () {
});

// TODO: this doesn't work because turning on strict mode breaks parsing sub-commands. why?
it("should exit with a helpful message if a non-existant command is provided", async function () {
it("should exit with a helpful message if a non-existent command is provided", async function () {
const logger = container.resolve("logger");

// this command does not exist
Expand All @@ -56,6 +56,22 @@ describe("cli operations", function () {
expect(container.resolve("parseYargs")).to.have.been.calledOnce;
});

it("should exit with a helpful message if no command is provided", async function () {
const logger = container.resolve("logger");

// no input
try {
await run("", container);
} catch (e) {}

expect(logger.stdout).to.not.be.called;
const message = `${chalk.reset(await builtYargs.getHelp())}\n\n${chalk.reset(
"Use 'fauna <command> --help' for more information about a command.",
)}`;
expect(logger.stderr).to.have.been.calledWith(message);
expect(container.resolve("parseYargs")).to.have.been.calledOnce;
});

it("should exit with a helpful message if the handler throws", async function () {
const logger = container.resolve("logger");

Expand Down

0 comments on commit 68d176d

Please sign in to comment.