-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.js
More file actions
79 lines (65 loc) · 2.08 KB
/
Copy pathcli.js
File metadata and controls
79 lines (65 loc) · 2.08 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
69
70
71
72
73
74
75
76
77
78
79
const commander = require('commander');
const pkginfo = require('pkginfo');
const parse = require('parse-duration');
const createDebug = require('debug');
const window = require('./window');
const DEBUG = createDebug('tournicoti:cli');
const MINIMUM_TIMEOUT_IN_SECONDS = 60;
const MINIMUM_ZOOM = 1;
pkginfo(module, 'version');
function assertTimeout(timeout) {
if (timeout < MINIMUM_TIMEOUT_IN_SECONDS * 1000) {
process.stderr.write(`Invalid timeout: value must be greater than: ${MINIMUM_TIMEOUT_IN_SECONDS} seconds.`);
process.exit(1);
}
}
function assertZoom(zoom) {
if (zoom < MINIMUM_ZOOM) {
process.stderr.write(`Invalid zoom: value must be greater than: ${MINIMUM_ZOOM}.`);
process.exit(1);
}
}
function main(url) {
if (!!commander.verbose) {
createDebug.enable('tournicoti:*');
}
DEBUG('URL addresses: %o', url);
if (!url || !url.length) {
commander.outputHelp();
process.exit(1);
} else {
const preventSleep = !!commander.preventSleep;
DEBUG('Prevent display: %o', preventSleep);
const randomUrl = !!commander.randomUrl;
DEBUG('Randomize URL addresses: %o', randomUrl);
const timeout = parse(commander.timeout);
assertTimeout(timeout);
DEBUG('Rotation timeout: %o', timeout);
const zoom = +commander.zoom;
assertZoom(zoom);
DEBUG('Zoom level: %o', zoom);
window.start({
preventSleep,
randomUrl,
timeout,
url,
zoom,
});
}
}
module.exports.initialize = () => {
commander
.version(module.exports.version)
.arguments('<url...>')
.option('--prevent-sleep', 'Prevent the display from going to sleep.')
.option('-r, --random-url', 'Randomly select the first URL to display.')
.option('-v, --verbose', 'Enable verbose mode.')
.option('-z, --zoom <level>', 'Changes the zoom level to the specified level.', MINIMUM_ZOOM)
.option(
'-t, --timeout <timeout>',
`Rotation timeout with human readable duration. Minimum: ${MINIMUM_TIMEOUT_IN_SECONDS}s.`,
`${MINIMUM_TIMEOUT_IN_SECONDS}s`,
)
.parse(process.argv);
main(commander.args);
};