-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
40 lines (36 loc) · 1000 Bytes
/
index.js
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
module.exports = function () {
return {
parse: function(program) {
program = program;
function checkLenght(program) {
if(program.args[0].length > 4096) {
throw Error('input maxlength > 4096');
}
return program;
}
var p = new Promise(function(resolve, reject) {
if (program.args.length < 1) {
process.stdin.setEncoding('utf8');
process.stdin.on('readable', () => {
var chunk = process.stdin.read();
if (chunk !== null) {
program.args[0] = chunk;
resolve(program);
} else if (!program.args[0]) {
program.help();
process.exit(1);
}
});
process.stdin.on('end', () => {
if (!program.args[0]) {
reject('no arguments');
}
});
} else {
resolve(program);
}
});
return p.then(checkLenght);
}
};
};