From 27939aea8224ba5b726923ee302f8d5177722ac7 Mon Sep 17 00:00:00 2001 From: Tilman Roeder Date: Mon, 27 Dec 2021 17:41:27 +0000 Subject: [PATCH] Add test for help messages --- src/command_test.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/command_test.ts b/src/command_test.ts index a927b01..fda8d8e 100644 --- a/src/command_test.ts +++ b/src/command_test.ts @@ -27,6 +27,22 @@ Deno.test("basic command errors", () => { }); }); +Deno.test("help messages shows closest flag", () => { + const cmd = new Command("A test command.") + .required(string, "test", { flags: ["test"] }); + + let message = ""; + try { + cmd.parse(["--tst", "test"]); + } catch (error) { + message = error.message; + } + assertEquals( + message, + "Unknown flag '--tst'\n\nHELP:\n\tDid you mean --test?", + ); +}); + Deno.test("can not have multiple anonymous optional arguments", () => { assertThrows(() => new Command("A test command.").optional(string, "first").optional(