-
Notifications
You must be signed in to change notification settings - Fork 2
/
cowsay.ts
103 lines (89 loc) · 2.42 KB
/
cowsay.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import * as cow from "./mod.ts"
import { parse } from "https://deno.land/std/flags/mod.ts";
import { IOptions } from "./src/models/IOptions.ts";
const opts = {
string: [
"text",
"cow",
"eyes",
"tongue"
],
boolean: [
"wrap",
"random",
"think",
"help",
"list"
],
alias: {
random: "r",
think: "k",
wrap: "w",
wrapLength: "wl",
help: "h",
text: "t",
cow: "c",
tongue: "g",
mode: "m",
eyes: "e",
list: "ls"
},
default: {
text: "Deno is great!",
cow: "cow",
eyes: "oo",
tongue: "U",
wrap: false,
wrapLength: 40,
mode: null,
random: false,
think: false,
help: false,
list: false
}
}
const help = `
arguments:
--text | -t: Message Text [ex: --text="Hello world" ]
--cow | -c: Cow image (default value is "cow") [ex: --cow="cat2" ]
--mode | -m: Predefined eyes/tonges (from 1 to 8) [ex: --mode=3]
--eyes | -e: Eyes of the image if exists (default: "oo") [ex: --eyes="@@" ]
--tongue | -g: Tongue of the image (default: "U") [ex: --tongue="V" ]
--random | -r: Pick random cow (default false) [ex: --random ]
--think | -k: Use think insted of say (default false) [ex: --think ]
--wrap | -w: Wrap the text (default false) [ex: --wrap ]
--wrapLength | --wl: Where the message should be wrapped (default 40) [ex: --wrapLength=10 ]
--list | --ls: List the available cows
example:
deno -A https://raw.githubusercontent.com/fakoua/cowsay/master/cowsay.ts -t="Hello World" -r
`;
async function main() {
const args = Deno.args
const argv = parse(args, opts)
if (argv.help) {
console.log(help)
Deno.exit(0)
}
if (argv.list) {
console.table(cow.list())
Deno.exit(0)
}
let res = ""
const options: IOptions = {
text: argv.text,
cow: argv.cow,
eyes: argv.eyes,
tongue: argv.tongue,
wrap: argv.wrap,
wrapLength: argv.wrapLength,
random: argv.random,
mode: argv.mode
}
if (argv.think) {
res = cow.think(options)
} else {
res = cow.say(options)
}
console.log(res)
}
main()