-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
58 lines (49 loc) · 1.29 KB
/
main.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
import { head } from './src/head.ts'
import { host } from './src/host.ts'
import { parse } from 'https://deno.land/[email protected]/flags/mod.ts'
import { ping } from './src/ping.ts'
const version = '0.3.1'
function handleGlobalOpt(args) {
if (args.h || args.help) {
printUsageAndExit(0)
} else if (args.v || args.version) {
console.log(`dnt v${version}`)
Deno.exit(0)
} else {
printUsageAndExit(1)
}
}
function printUsageAndExit(exitcode: number) {
console.log(`USAGE: dnt [ global options ] <command> [ options ] <host>
DESCRIPTION
dnt (v${version}) is a collection of lightweight networking utilities.
See COMMANDS for supported features.
COMMANDS:
* head
* host
* ping
GLOBAL OPTIONS
-h, --help Print this help message
-v, --version Print dnt version
Tip: use -h with each command to learn more, e.g. \`dnt ping -h'`)
Deno.exit(exitcode)
}
// Enter main loop
if (import.meta.main) {
const userArgs = parse(Deno.args)
// Parse and validate user-supplied arguments and options.
if (userArgs._.length === 0) handleGlobalOpt(userArgs)
switch (userArgs._[0]) {
case 'head':
head(userArgs)
break
case 'host':
host(userArgs)
break
case 'ping':
ping(userArgs)
break
default:
printUsageAndExit(1)
}
}