forked from garris/BackstopJS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathusage.js
53 lines (46 loc) · 1.91 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
51
52
53
const version = require('../package.json').version;
const makeSpaces = require('../core/util/makeSpaces');
const commandsDescription = {
test: 'Create test screenshots and compare against the set you previously approved/referenced.',
approve: 'Promotes all test bitmaps from last test run to reference bitmaps.',
reference: 'Creates new reference screenshots. Deletes all existing reference files.',
init: 'Generate BackstopJS boilerplate files in your CWD. NOTE: Overwrites existing config files!',
remote: 'Launch BackstopJS remote service.',
openReport: 'View the last test report in your browser.'
};
const optionsDescription = {
'--config': 'Path to config file name',
'--filter': 'A RegEx string used to filter by scenario labels when running "test", "reference", or "approve" commands',
'-h, --help': 'Display usage',
'-v, --version': 'Display version',
'-i': 'Prevent deletion of non-matching reference files when running "reference" command (newer matching reference files are still overwritten)'
};
function makeDescription (descriptions) {
return Object.keys(descriptions)
.map(function (commandName) {
return makeSpaces(4) + commandName + spacesBetweenCommandAndDescription(commandName) + descriptions[commandName];
})
.join('\n');
}
// Number of spaces to echo before writing description
const 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);
function spacesBetweenCommandAndDescription (commandName) {
return makeSpaces(2 + leftPaddingOfDescription - commandName.length);
}
const usage = '\
Welcome to BackstopJS ' + version + ' CLI\n\
\n\
Commands:\n\
' + makeDescription(commandsDescription) + '\n\
\n\
Options:\n\
' + makeDescription(optionsDescription) + '\n\
\n';
module.exports = usage;