From ece0c76d7ed3ee004b3e308889d6e211e5148a57 Mon Sep 17 00:00:00 2001 From: ryu <114303361+ryuapp@users.noreply.github.com> Date: Wed, 14 Aug 2024 20:57:07 +0900 Subject: [PATCH] chore: show help if input does not exist --- src/cli.ts | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/cli.ts b/src/cli.ts index 544bfe7..ab9ec42 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -18,6 +18,19 @@ import { exists } from "@std/fs/exists"; import { mdToPdf } from "./md-to-pdf.ts"; import { getFilename } from "./utils/filename.ts"; +function printHelp() { + const help = `md2pdf: ${ + green("A simple CLI tool for converting markdown to PDF.") + } + +${gray("Usage:")} ${green("md2pdf [OPTION]... [FILE]...")} + +${yellow("Options:")} + ${green("-w, --watch")} Watch for file changes. + ${green("-h, --help")} Print help.`; + console.log(help); +} + async function generatePdfFromMarkdown(path: string) { const pdfName = getFilename(path) + ".pdf"; @@ -38,16 +51,7 @@ async function generatePdfFromMarkdown(path: string) { const args = await parseArgs(Deno.args); if (args.h || args.help) { - const help = `md2pdf: ${ - green("A simple CLI tool for converting markdown to PDF.") - } - -${gray("Usage:")} ${green("md2pdf [OPTION]... [FILE]...")} - -${yellow("Options:")} - ${green("-w, --watch")} Watch for file changes. - ${green("-h, --help")} Print help.`; - console.log(help); + printHelp(); Deno.exit(0); } @@ -73,6 +77,11 @@ if (args._) { } } +if (paths.length < 1) { + printHelp(); + Deno.exit(0); +} + await (async () => { for (let i = 0; i < paths.length; i++) { await generatePdfFromMarkdown(paths[i]);