Skip to content

Commit

Permalink
feat: (*) Add --help flag
Browse files Browse the repository at this point in the history
  • Loading branch information
dperuo committed Mar 22, 2024
1 parent ba51197 commit 9bd2bcc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
9 changes: 7 additions & 2 deletions cli.ts
Original file line number Diff line number Diff line change
@@ -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));
Expand Down
11 changes: 11 additions & 0 deletions src/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export const CharSets = {
} as const;

export const options: ParseOptions = {
boolean: ['help'],

alias: {
count: "c",
size: "s",
Expand All @@ -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.
`;

0 comments on commit 9bd2bcc

Please sign in to comment.