-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
executable file
·55 lines (47 loc) · 1.5 KB
/
index.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
54
55
#!/usr/bin/env node
const program = require('commander');
var clear = require('clear');
var figlet = require('figlet');
const chalk = require('chalk');
const {interpretBarcode} = require('./lib/logic');
program
.version(require('./package.json').version, '-v, --version')
.description('Onlineticket CLI Parser for UIC-918.3 barcodes');
program
.usage('[options] <file ...>')
.option('-i, --image', 'if file is an image (png,jpeg,...)')
.option('-s, --signature', 'verify the barcode signature')
.parse(process.argv);
if (program.args.length > 0) {
// ONE OR MORE ARGUMENTS GIVEN
if (program.image) {
//console.log(program.args);
drawIntro();
const verifySignature = program.signature
const opts = verifySignature ? {verifySignature: true} : {}
// console.log(opts)
program.args.forEach((file_path) => interpretBarcode(file_path, opts));
} else {
// DON'T KNOW HOW TO HANDLE THAT FILE:
err('No file type argument (--image, --pdf, ...) passed.');
}
} else {
// NO ARGUMENTS GIVEN
err('No arguments given.');
program.help();
}
function drawIntro () {
clear();
const repo_name = capitalizeFirstLetter(require('./package.json').name) + '.js';
console.log(
chalk.yellow(
figlet.textSync(repo_name, { font: 'Standard', horizontalLayout: 'full' })
)
);
}
function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
function err(string) {
console.error(chalk.red(`\n ERROR: ${string}\n`));
}