]> git.ardis.lu - seed-phrase-transposer/commitdiff
Add special exit case for no input
authorArdis Lu <ardisglu@gmail.com>
Sat, 13 Jan 2024 06:54:02 +0000 (22:54 -0800)
committerArdis Lu <ardisglu@gmail.com>
Sat, 13 Jan 2024 06:54:02 +0000 (22:54 -0800)
The original message for no input ("Seed phrase of length 1 can't be arranged into a grid") does not make sense.

main.ts
main_test.ts

diff --git a/main.ts b/main.ts
index 9270ab035eb2fbf812d1bdc5511fd02df05ad4c6..2f77e632c0534a157770557d6a7fd88c396c84ed 100644 (file)
--- a/main.ts
+++ b/main.ts
@@ -68,6 +68,13 @@ export function getLowerFactors(num: number): Array<number> {
  */
 export function main() {
   const input = prompt("Seed phrase:");
+  if (input === "") {
+    console.error(
+      "%c\nNo input provided. Enter a seed phrase to check permutations.",
+      "color: red",
+    );
+    Deno.exit(0);
+  }
   const words = parseInput(input);
   const factors = getLowerFactors(words.length);
   if (factors.length === 0) {
index 7ab078d2c00d4e7cf48b5d3930d95008c94e92e2..27fe3acd013a77940417ac603377d932f7011fdd 100644 (file)
@@ -212,3 +212,18 @@ Deno.test("main exits cleanly on a malformed seed phrase", () => {
   consoleSpy.restore();
   promptStub.restore();
 });
+
+Deno.test("main exits cleanly on no input", () => {
+  const consoleSpy = spy(console, "error");
+  const promptStub = stub(
+    globalThis,
+    "prompt",
+    () => "",
+  );
+
+  assertThrows(main);
+  assertSpyCalls(consoleSpy, 1);
+
+  consoleSpy.restore();
+  promptStub.restore();
+});
This page took 0.034275 seconds and 4 git commands to generate.