From 9bd2bcc2137f364bafbeba371ff7b2d71392e9ab Mon Sep 17 00:00:00 2001 From: dperuo Date: Fri, 22 Mar 2024 10:51:39 -0500 Subject: [PATCH] feat: (*) Add --help flag --- cli.ts | 9 +++++++-- src/const.ts | 11 +++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/cli.ts b/cli.ts index aeead4c..0958a7d 100644 --- a/cli.ts +++ b/cli.ts @@ -1,8 +1,13 @@ import { parseArgs } from "./deps.ts"; -import { options } from "./src/const.ts"; +import { options, USAGE } from "./src/const.ts"; import { sweetid } from "./src/main.ts"; -const { count, size } = parseArgs(Deno.args, options); +const { count, size, help } = parseArgs(Deno.args, options); + +if (help) { + console.log(USAGE); + Deno.exit(); +} for (let i = count; i > 0; i--) { console.log(sweetid(size)); diff --git a/src/const.ts b/src/const.ts index 09c6878..4e22a8a 100644 --- a/src/const.ts +++ b/src/const.ts @@ -29,6 +29,8 @@ export const CharSets = { } as const; export const options: ParseOptions = { + boolean: ['help'], + alias: { count: "c", size: "s", @@ -38,4 +40,13 @@ export const options: ParseOptions = { count: 1, size: "xshort", }, + + unknown: () => { + console.log(USAGE); + Deno.exit(1); + } }; + +export const USAGE = ` +See https://deno.land/x/sweetid for details. +`;