Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If no command is given show help text; and instructions on sub-help. Include a dev quick start in the README #429

Merged
merged 2 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions DEV-README.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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use this without having a build so in this example...build isn't necessary. So depending on what your intent here is, you may need to change this.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests require builds (b/c we assert things on the behavior of the prod bundle), so I think it's reasonable to include?

Copy link
Contributor Author

@cleve-fauna cleve-fauna Nov 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i put this in to make sure your stuff wasn't roont.

Make sense?

Cause my stuff was roont.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'll add some comments so noone else brain freezes when they read it.

```



### 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 () {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oopsie

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