From ed0ef62eea0c9c9d60798040d039517203b6817f Mon Sep 17 00:00:00 2001 From: David Crespo Date: Fri, 1 Dec 2023 15:07:03 -0600 Subject: [PATCH] minor tweaks to api-diff script --- tools/deno/api-diff.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tools/deno/api-diff.ts b/tools/deno/api-diff.ts index e0d2feef2..865065d7c 100755 --- a/tools/deno/api-diff.ts +++ b/tools/deno/api-diff.ts @@ -31,6 +31,11 @@ Parameters: PR number : If left out, interactive picker is shown `.trim() +function printHelpAndExit() { + console.log(HELP) + Deno.exit() +} + // inspired by: https://github.com/dsherret/dax/issues/137#issuecomment-1603848769 declare module 'https://deno.land/x/dax@0.35.0/mod.ts' { interface CommandBuilder { @@ -55,8 +60,7 @@ async function pickPr() { const prNum = await listPRs().pipe(picker()).pipe(cut()).text() if (!/^\d+$/.test(prNum)) { - console.error(`Error picking PR. Expected number, got '${prNum}'`) - Deno.exit() + throw new Error(`Error picking PR. Expected number, got '${prNum}'`) } return parseInt(prNum, 10) } @@ -101,16 +105,12 @@ const args = flags.parse(Deno.args, { boolean: ['force', 'help'], }) -if (args.help) { - console.log(HELP) - Deno.exit() -} +if (args.help) printHelpAndExit() const prNum = args._[0] ? args._[0] : await pickPr() if (typeof prNum !== 'number') { - console.error(`PR number must be a number. Got '${prNum}' instead.`) - Deno.exit() + throw new Error(`PR number must be a number. Got '${prNum}' instead.`) } const { base, head } = await getPrRange(prNum)