forked from garris/BackstopJS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathusage.js
50 lines (43 loc) · 1.74 KB
/
usage.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
41
42
43
44
45
46
47
48
49
50
var version = require('../package.json').version;
var makeSpaces = require('../core/util/makeSpaces');
var commandsDescription = {
test: 'Create test screenshots and compare against the set you previously approved/referenced using `backstop approve` or `backstop reference`.',
approve: 'Promotes all test bitmaps from last test run to reference bitmaps.',
reference: 'Creates new reference screenshots. Deletes all existing reference bitmaps.',
init: '(alias: genConfig) Generate a configuration file boilerplate in your current directory. PLEASE NOTE: this will overwrite all existing backstop data! Use only if you want a fresh start.',
openReport: 'View your last test screenshots in your browser.'
};
var optionsDescription = {
'-h, --help': 'Display usage',
'-v, --version': 'Display version',
'-i': 'Incremental reference generation'
};
function makeDescription (descriptions) {
return Object.keys(descriptions)
.map(function (commandName) {
return makeSpaces(4) + commandName + spacesBetweenCommandAndDescription(commandName) + descriptions[commandName];
})
.join('\n');
}
function spacesBetweenCommandAndDescription (commandName) {
return makeSpaces(2 + leftPaddingOfDescription - commandName.length);
}
// Number of spaces to echo before writing description
var leftPaddingOfDescription = Object.keys(commandsDescription)
.concat(Object.keys(optionsDescription))
.map(function (string) {
return string.length;
})
.reduce(function maxReducer (max, length) {
return Math.max(max, length);
}, 0);
var usage = '\
Welcome to BackstopJS ' + version + ' CLI\n\
\n\
Commands:\n\
' + makeDescription(commandsDescription) + '\n\
\n\
Options:\n\
' + makeDescription(optionsDescription) + '\n\
\n';
module.exports = usage;