forked from piuccio/cowsay
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.js
More file actions
58 lines (53 loc) · 1.7 KB
/
cli.js
File metadata and controls
58 lines (53 loc) · 1.7 KB
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
#!/usr/bin/env node
var argv = require("optimist")
.usage("Usage: $0 [-e eye_string] [-f cowfile] [-h] [-l] [-n] [-T tongue_string] [-W column] [-bdgpstwy] text\n\n" +
"If any command-line arguments are left over after all switches have been processed, they become the cow's message.\n\n" +
"If the program is invoked as cowthink then the cow will think its message instead of saying it.")
.options({
"e" : {
default : "oo"
},
"T" : {
default : " "
},
"W" : {
default : 40
},
"f" : {
default : "default"
}
})
.describe({
"b" : "Mode: Borg",
"d" : "Mode: Dead",
"g" : "Mode: Greedy",
"p" : "Mode: Paranoia",
"s" : "Mode: Stoned",
"t" : "Mode: Tired",
"w" : "Mode: Wired",
"y" : "Mode: Youthful",
"e" : "Select the appearance of the cow's eyes.",
"T" : "The tongue is configurable similarly to the eyes through -T and tongue_string.",
"h" : "Display this help message",
"n" : "If it is specified, the given message will not be word-wrapped.",
"W" : "Specifies roughly where the message should be wrapped. The default is equivalent to -W 40 i.e. wrap words at or before the 40th column.",
"f" : "Specifies a cow picture file (''cowfile'') to use. It can be either a path to a cow file or the name of one of cows included in the package.",
"l" : "List all cowfiles included in this package."
})
.boolean(["b", "d", "g", "p", "s", "t", "w", "y", "n", "h", "l"])
.argv;
if (argv.l) {
listCows();
} else if (argv.h || argv._.length === 0) {
require("optimist").showHelp();
} else {
say();
}
function say () {
var module = require("./index");
var think = /think$/.test(argv["$0"]);
console.log(think ? module.think(argv) : module.say(argv));
}
function listCows () {
require("./lib/cows").list();
}