forked from jamesryanbell/node-wraith
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.js
More file actions
69 lines (58 loc) · 1.36 KB
/
cli.js
File metadata and controls
69 lines (58 loc) · 1.36 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
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env node
'use strict';
var nopt = require('nopt'),
chalk = require('chalk'),
wraith = require('./index');
function showHelp() {
console.log('A responsive screenshot comparison tool.');
console.log('Based on the Ruby version available at http://github.com/BBC-News/wraith');
console.log('');
console.log(chalk.underline('Usage'));
console.log(' wraith --config <file>');
console.log('');
console.log(chalk.underline('Example'));
console.log(' wraith --config chrome');
console.log('');
}
function getStdin(cb) {
var ret = '';
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function (data) {
ret += data;
});
process.stdin.on('end', function () {
cb(ret);
});
}
function init(args) {
if ( opts.help ) { return showHelp(); }
if ( opts.version ) { return console.log(require('./package').version); }
if ( opts.config ) {
if ( args[0] === '' ) {
console.error(chalk.yellow('You must specifiy a configuration file'));
return showHelp();
} else {
return wraith.run(args[0]);
}
}
return showHelp();
}
var opts = nopt({
help: Boolean,
version: Boolean,
config: Boolean
}, {
h: '--help',
v: '--version',
c: '--config'
});
var args = opts.argv.remain;
if (process.stdin.isTTY) {
init(args);
} else {
getStdin(function (data) {
[].push.apply(args, data.trim().split('\n'));
init(args);
});
}