-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcli.js
37 lines (32 loc) · 931 Bytes
/
cli.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
var program = require('commander')
var pdf_narcissist = require('.')
var exists = require('path-exists').sync
function checkFile (file, name) {
if (!file) {
console.log('ERROR: you must provide an', name)
process.exit(1)
} else if (/^input/.test(name) && !exists(file)) {
console.log('ERROR:', name, "file doesn't exist at path", file)
process.exit(1)
}
}
program
.version(require('./package.json').version)
program
.command('encode <pdf> <png>')
.description('encode a PDF into a PNG thumbnail of itself')
.action(function (pdf, png) {
checkFile(pdf, 'input pdf')
checkFile(png, 'output png')
pdf_narcissist.encode(pdf, png)
})
program
.command('decode <png> <pdf>')
.description('extract a PDF from a PNG')
.action(function (png, pdf) {
checkFile(png, 'input png')
checkFile(pdf, 'output pdf')
pdf_narcissist.decode(png, pdf)
})
program
.parse(process.argv)