deno.land / x / denon@2.5.0 / src / args.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright 2020-2021 the denosaurs team. All rights reserved. MIT license.
/** Regex to test if string matches version format */const reVersion = /^v?[0-9]+\.[0-9]+\.[0-9]+$/;
/** Map of supported flags that modify * `denon` behavior. */export interface Args { help: boolean; version: boolean;
init?: string; upgrade?: string; config?: string;
cmd: string[];}
/** Parse Deno.args into a flag map (`Args`) * to be handled by th CLI. */export function parseArgs(args: string[] = Deno.args): Args { if (args[0] === "--") { args = args.slice(1); }
const flags: Args = { help: false, version: false, init: undefined, upgrade: undefined, config: undefined, cmd: [], };
if ((args.includes("--config") || args.includes("-c")) && args.length > 1) { flags.config = args[1]; args = args.slice(2); }
if (args.includes("--help") || args.includes("-h")) { flags.help = true; args = args.slice(1); }
if (args.includes("--version") || args.includes("-v")) { flags.version = true; args = args.slice(1); }
if (args.includes("--init") || args.includes("-i")) { const index = args.includes("--init") ? args.indexOf("--init") : args.indexOf("-i"); const next = args[index + 1];
if (next) { flags.init = next; args = args.slice(2); } else { flags.init = "json"; args = args.slice(1); } }
if (args.includes("--upgrade") || args.includes("-u")) { const index = args.includes("--upgrade") ? args.indexOf("--upgrade") : args.indexOf("-u"); const next = args[index + 1];
if (next && (next === "latest" || reVersion.test(next))) { flags.upgrade = !next.startsWith("v") || next !== "latest" ? "v" + next : next; args = args.slice(2); } else { flags.upgrade = "latest"; args = args.slice(1); } }
flags.cmd = args; return flags;}
denon

Version Info

Tagged at
2 years ago

External Dependencies

No external dependencies 🎉