-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.ts
55 lines (51 loc) · 1.29 KB
/
cli.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { parse } from "https://deno.land/std@0.198.0/flags/mod.ts";
import { ulid } from "./mod.ts";
const { args } = Deno;
const parsed = parse(args);
let timestamp: number | undefined = undefined;
let help = false;
let batch = 1;
const helpmsg = `
Usage: ulid
Options:
-h, --help: displays a help message
-t, --time: <t:number> seed a given timestamp
-n, --number: <n:number> generate n amount of ULIDs
`;
for (const flag of Object.keys(parsed)) {
switch (flag) {
case "_":
break;
case "h":
case "help":
help = true;
break;
case "t":
if (typeof parsed["t"] === "number") timestamp = parsed["t"];
else help = true;
break;
case "time":
if (typeof parsed["time"] === "number") timestamp = parsed["time"];
else help = true;
break;
case "n":
if (typeof parsed["n"] === "number") batch = parsed["n"];
else help = true;
break;
case "number":
if (typeof parsed["number"] === "number") batch = parsed["number"];
else help = true;
break;
default:
console.log("Unknown flag provided.");
help = true;
}
}
if (!help) {
while (batch) {
console.log(ulid(timestamp));
batch--;
}
} else {
console.log(helpmsg);
}