From 4d8b0b85dd6f697167752e81d231239f5879b5fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Ml=C3=A1dek?= Date: Mon, 20 Sep 2021 22:40:12 +0200 Subject: [PATCH] cli - use proper defaults --- cli/main.ts | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/cli/main.ts b/cli/main.ts index 9587de9..5b99e30 100644 --- a/cli/main.ts +++ b/cli/main.ts @@ -11,13 +11,19 @@ import { walkSync } from "https://deno.land/std@0.107.0/fs/mod.ts"; const args = parse(Deno.args, { alias: { - "w": "width", - "h": "height", - "o": "output", - "m": "mode", - "r": "recursive", + w: "width", + h: "height", + o: "output", + m: "mode", + r: "recursive", }, boolean: ["recursive"], + default: { + w: 640, + h: 640, + include: "*.png, *.jpg", + output: "collage.png" + } }); if (args["mode"] === true) { @@ -27,7 +33,7 @@ if (args["mode"] === true) { const files: Set = new Set(); const includeExtensions = Array.from( - String(args["include"] || "*.png, *.jpg").matchAll(/\*\.([\w]+)/g), + String(args["include"]).matchAll(/\*\.([\w]+)/g), ).map(([_, group]) => group); args["_"].forEach((arg) => { @@ -68,7 +74,7 @@ if (args["mode"]) { allModeKeys.push(...displayCollageModeType); } -const canvas = createCanvas(args["width"] || 640, args["height"] || 640); +const canvas = createCanvas(args["width"], args["height"]); const context = canvas.getContext("2d"); const collageConfig: CollageConfig = { @@ -98,6 +104,6 @@ if (modeKey === "recursive") { mode.place(context, images, segments); } -const output = args["output"] || "collage.png"; +const output = args["output"]; console.log(`Saving to "${output}"...`); await Deno.writeFile(output, canvas.toBuffer());