This commit is contained in:
Jarred Sumner
2023-12-09 21:59:27 -08:00
parent 300d17f223
commit 54f1f4635e
2 changed files with 35 additions and 8 deletions

View File

@@ -1521,14 +1521,9 @@ pub const Command = struct {
}
break :brk false;
};
if (print_help) {
Command.Tag.printHelp(.CreateCommand, true);
Global.exit(0);
return;
}
var template_name_start: usize = 0;
var positionals: [2]string = undefined;
var positionals: [2]string = .{ "", "" };
var positional_i: usize = 0;
@@ -1547,6 +1542,16 @@ pub const Command = struct {
}
}
if (print_help or
// "bun create --"
// "bun create -abc --"
positional_i == 0)
{
Command.Tag.printHelp(.CreateCommand, true);
Global.exit(0);
return;
}
const template_name = positionals[0];
// if template_name is "react"

View File

@@ -1,5 +1,5 @@
import { spawn } from "bun";
import { afterEach, beforeEach, expect, it } from "bun:test";
import { spawn, spawnSync } from "bun";
import { afterEach, beforeEach, expect, it, describe } from "bun:test";
import { bunExe, bunEnv as env } from "harness";
import { mkdtemp, realpath, rm, mkdir, stat } from "fs/promises";
import { tmpdir } from "os";
@@ -14,6 +14,28 @@ afterEach(async () => {
await rm(x_dir, { force: true, recursive: true });
});
describe("should not crash", async () => {
const args = [
[bunExe(), "create", ""],
[bunExe(), "create", "--"],
[bunExe(), "create", "--", ""],
[bunExe(), "create", "--help"],
];
for (let cmd of args) {
it(JSON.stringify(cmd.slice(1).join(" ")), () => {
const { exitCode } = spawnSync({
cmd,
cwd: x_dir,
stdout: "ignore",
stdin: "inherit",
stderr: "inherit",
env,
});
expect(exitCode).toBe(cmd.length === 3 && cmd.at(-1) === "" ? 1 : 0);
});
}
});
it("should create selected template with @ prefix", async () => {
const { stderr } = spawn({
cmd: [bunExe(), "create", "@quick-start/some-template"],