forked from nbqx/fakestk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd.js
executable file
·34 lines (30 loc) · 839 Bytes
/
cmd.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
#!/usr/bin/env node
var fakestk = require('./index');
var path = require('path');
if(process.stdin.isTTY){
var argv = require('minimist')(process.argv.slice(2),{}),
fs = require('fs');
if(argv.h || argv.help){
return fs.createReadStream(__dirname+'/resources/usage.txt').pipe(process.stdout);
}
if(argv._.length!==0){
var script = path.resolve(argv._[0]);
fakestk.run(script,function(err,result){
if(err) return console.log(err.toString());
if(result!==''){
console.log(result);
}
});
}
}else{
var input = '';
process.stdin.on('data',function(c){ input += c });
process.stdin.on('end',function(){
fakestk.run(input,function(err,result){
if(err) return console.log(err.toString());
if(result!==''){
console.log(result);
}
});
});
}