diff --git a/README.md b/README.md index 97f53c7..a3e7a93 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ Usage: md2pdf [OPTION]... [FILE]... Options: -w, --watch Watch for file changes. -h, --help Print help. - --css Set CSS file used for rendering. + --stylesheet Set CSS file path used for rendering. ``` ## Front matter (Experimental) diff --git a/deno.json b/deno.json index cb557ea..b7b9b58 100644 --- a/deno.json +++ b/deno.json @@ -8,10 +8,10 @@ "tasks": { "cli": "deno run --allow-read --allow-write --allow-env --allow-net=0.0.0.0,127.0.0.1 --allow-run ./src/cli.ts --", "dev": "deno run --allow-read --allow-write --allow-env --allow-net=0.0.0.0,127.0.0.1 --allow-run ./src/cli.ts -- README.md", - "dev:all": "deno run --allow-read --allow-write --allow-env --allow-net=0.0.0.0,127.0.0.1 --allow-run ./src/cli.ts -w --css=src/testdata/bluecode.css -- README.md", + "dev:all": "deno run --allow-read --allow-write --allow-env --allow-net=0.0.0.0,127.0.0.1 --allow-run ./src/cli.ts -w --stylesheet=src/testdata/bluecode.css -- README.md", "dev:help": "deno run --allow-read --allow-write --allow-env --allow-net=0.0.0.0,127.0.0.1 --allow-run ./src/cli.ts --help", "dev:css": "deno run --allow-read --allow-write --allow-env --allow-net=0.0.0.0,127.0.0.1 --allow-run ./src/cli.ts -- ./src/testdata/bluecode.md", - "dev:invalidcss": "deno run --allow-read --allow-write --allow-env --allow-net=0.0.0.0,127.0.0.1 --allow-run ./src/cli.ts --css=src/testdata/redcode.css -- README.md", + "dev:invalidcss": "deno run --allow-read --allow-write --allow-env --allow-net=0.0.0.0,127.0.0.1 --allow-run ./src/cli.ts --stylesheet=src/testdata/redcode.css -- README.md", "dev:watch": "deno run --allow-read --allow-write --allow-env --allow-net=0.0.0.0,127.0.0.1 --allow-run ./src/cli.ts --watch -- README.md" }, "imports": { diff --git a/src/cli.ts b/src/cli.ts index fa5fbad..4da0f1d 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -25,24 +25,6 @@ import { mdToPdf } from "./md-to-pdf.ts"; import { getFilename } from "./utils/filename.ts"; import type { MdToPdfOptions } from "./types.ts"; -async function validateArgs( - args: { - css?: string; - }, -): Promise { - if (args.css) { - try { - await Deno.lstat(args.css); - } catch (_e) { - console.error( - `${brightRed("error")}: Set CSS file is not found: ${args.css}`, - ); - return false; - } - } - return true; -} - function printHelp(): void { const help = `md2pdf: ${ green("A simple CLI tool for converting markdown to PDF.") @@ -53,7 +35,7 @@ ${gray("Usage:")} ${green("md2pdf [OPTION]... [FILE]...")} ${yellow("Options:")} ${green("-w, --watch")} Watch for file changes. ${green("-h, --help")} Print help. - ${green("--css")} Set CSS file used for rendering.`; + ${green("--stylesheet")} Set CSS file path used for rendering.`; console.log(help); } @@ -78,12 +60,10 @@ async function generatePdfFromMarkdown(path: string, options?: MdToPdfOptions) { const args = await parseArgs(Deno.args, { boolean: ["w", "watch", "h", "help"], - string: ["css"], + string: ["stylesheet"], }); -if (!(await validateArgs(args))) { - Deno.exit(1); -} else if (args.h || args.help) { +if (args.h || args.help) { printHelp(); Deno.exit(0); } diff --git a/src/types.ts b/src/types.ts index ed6b46c..07d5584 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,3 +1,3 @@ export type MdToPdfOptions = { - css?: string; + stylesheet?: string; }; diff --git a/src/utils/server.ts b/src/utils/server.ts index 689e0ae..a1ba347 100644 --- a/src/utils/server.ts +++ b/src/utils/server.ts @@ -40,7 +40,7 @@ export function launchHttpServer( } catch (_e) { markdown = fileContent; } - stylesheet = options?.css ? options?.css : stylesheet; + stylesheet = options?.stylesheet ?? stylesheet; const content = mdToHtml(markdown); const title = getFilename(path.split("/").at(-1) || "") || "Untitled";