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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
var nomnom = require("../nomnom");
function strip(str) {
return str.replace(/\s+/g, '');
}
exports.testCallback = function(test) {
test.expect(1);
var parser = nomnom();
parser.command('run').callback(function(options) {
test.equal(options.v, 3);
});
parser.command('other').callback(function() {
test.ok(false, "callback for other command shouldn't be called");
});
parser.parse(["run","-v", "3"]);
test.done();
}
exports.testMissingCommand = function(test) {
test.expect(1);
var parser = nomnom().scriptName("test");
parser.command('run');
parser.printer(function(string) {
test.equal(string, "test: no such command 'other'");
test.done();
});
parser.parse(["other"]);
}
exports.testNoCommand = function(test) {
test.expect(2);
var parser = nomnom();
parser.nocommand()
.options({
version: {
flag: true
}
})
.callback(function(options) {
test.strictEqual(options.version, true);
})
.usage("fallback usage");
parser.command('run');
var options = parser.parse(["--version"]);
test.strictEqual(options.version, true);
test.done();
}
function createParser() {
var parser = nomnom().scriptName("test")
.options({
debug: {
flag: true
}
});
parser.command('run')
.options({
file: {
help: 'file to run'
}
})
.help("run all");
parser.command('test').usage("test usage");
parser.nocommand()
.options({
verbose: {
flag: true
}
})
.help("nocommand");
return parser;
}
exports.testUsage = function(test) {
test.expect(4);
var parser = createParser();
parser.printer(function(string) {
test.equal(strip(string), "testusage");
});
parser.parse(["test", "-h"]);
parser = createParser().nocolors();
parser.printer(function(string) {
test.equal(strip(string), "Usage:testrun[options]Options:--debug--filefiletorunrunall");
});
parser.parse(["run", "-h"]);
parser = createParser().nocolors();
parser.printer(function(string) {
test.equal(strip(string), "Usage:test[command][options]commandoneof:run,testOptions:--debug--verbosenocommand");
});
parser.parse(["-h"]);
parser = createParser().nocolors();
parser.nocommand()
.usage("fallback");
parser.printer(function(string) {
test.equal(strip(string), "fallback");
});
parser.parse(["-h"]);
test.done();
}
|