Skip to content

Commit

Permalink
chore: show help if input does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
ryuapp committed Aug 14, 2024
1 parent b179ada commit ece0c76
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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);
}

Expand All @@ -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]);
Expand Down

0 comments on commit ece0c76

Please sign in to comment.