From fe792455ab06b7f0615c0ea19da6b99e37732df7 Mon Sep 17 00:00:00 2001 From: Marvin Hagemeister Date: Wed, 29 Nov 2023 16:57:39 +0100 Subject: [PATCH] fix: add missing `-h/--help` to init (#2096) --- init.ts | 10 +++++++++- tests/init_test.ts | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/init.ts b/init.ts index 20fd2f99..64eec5a6 100644 --- a/init.ts +++ b/init.ts @@ -39,10 +39,18 @@ const USE_TAILWIND_MESSAGE = const USE_VSCODE_MESSAGE = "Do you use VS Code?"; const flags = parse(Deno.args, { - boolean: ["force", "tailwind", "vscode", "docker"], + boolean: ["force", "tailwind", "vscode", "docker", "help"], default: { "force": null, "tailwind": null, "vscode": null, "docker": null }, + alias: { + help: "h", + }, }); +if (flags.help) { + console.log(help); + Deno.exit(0); +} + console.log(); console.log( colors.bgRgb8( diff --git a/tests/init_test.ts b/tests/init_test.ts index dbf7926e..5b0ad0b8 100644 --- a/tests/init_test.ts +++ b/tests/init_test.ts @@ -13,6 +13,7 @@ import { assertTextMany, clickWhenListenerReady, fetchHtml, + getStdOutput, startFreshServer, waitForText, } from "./test_utils.ts"; @@ -454,3 +455,43 @@ Deno.test({ await retry(() => Deno.remove(tmpDirName, { recursive: true })); }, }); + +Deno.test("init - show help screen", async (t) => { + await t.step("--help", async () => { + const output1 = await new Deno.Command(Deno.execPath(), { + args: [ + "run", + "-A", + "--no-config", + "init.ts", + "--help", + ], + stdin: "null", + stdout: "piped", + stderr: "piped", + }).output(); + + assertEquals(output1.code, 0); + const { stdout } = getStdOutput(output1); + assertStringIncludes(stdout, "Initialize a new Fresh project"); + }); + + await t.step("-h", async () => { + const output1 = await new Deno.Command(Deno.execPath(), { + args: [ + "run", + "-A", + "--no-config", + "init.ts", + "-h", + ], + stdin: "null", + stdout: "piped", + stderr: "piped", + }).output(); + + assertEquals(output1.code, 0); + const { stdout } = getStdOutput(output1); + assertStringIncludes(stdout, "Initialize a new Fresh project"); + }); +});