From f7b12852fa8a6f557757dd3482c2b0b3f2aa4e45 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 10 Mar 2024 18:28:01 +0900 Subject: feat(blog/nuldoc): add --date option to "new" command to change date in path --- vhosts/blog/nuldoc-src/commands/new.ts | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'vhosts/blog/nuldoc-src/commands') diff --git a/vhosts/blog/nuldoc-src/commands/new.ts b/vhosts/blog/nuldoc-src/commands/new.ts index db1faf72..19002531 100644 --- a/vhosts/blog/nuldoc-src/commands/new.ts +++ b/vhosts/blog/nuldoc-src/commands/new.ts @@ -1,20 +1,36 @@ import { dirname, join } from "std/path/mod.ts"; import { ensureDir } from "std/fs/mod.ts"; +import { parse } from "std/flags/mod.ts"; import { Config } from "../config.ts"; export async function runNewCommand(config: Config) { - const type = Deno.args[1]; + const parsedArgs = parse(Deno.args, { + string: ["date"], + }); + + const type = parsedArgs._[1]; if (type !== "post" && type !== "slide") { console.log(`Usage: nuldoc new - must be either post or slide.`); + must be either "post" or "slide". + +OPTIONS: + --date +`); Deno.exit(1); } - const now = new Date(); - const ymd = `${now.getFullYear()}-${ - (now.getMonth() + 1).toString().padStart(2, "0") - }-${now.getDate().toString().padStart(2, "0")}`; + const ymd = (() => { + if (parsedArgs.date) { + return parsedArgs.date; + } + + const now = new Date(); + const y = now.getFullYear(); + const d = (now.getMonth() + 1).toString().padStart(2, "0"); + const m = now.getDate().toString().padStart(2, "0"); + return `${y}-${d}-${m}`; + })(); const destFilePath = join( Deno.cwd(), -- cgit v1.2.3-70-g09d2