-
Notifications
You must be signed in to change notification settings - Fork 2
/
cli.js
executable file
·39 lines (35 loc) · 1.08 KB
/
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
38
#!/usr/bin/env node
const { create, extract } = require('./index')
const fs = require('fs-extra')
const argv = require('yargs')
.command('create', 'create a powfile')
.option('image', {
alias: 'i',
description:`The png image you'd like to encode the data into`
})
.option('output', {
alias: 'o',
description: 'The output file name (should also be a png)'
})
.command('extract <input png>')
.option('dir', {
alias: 'd',
description: 'The output directory'
})
.option('--no-unzip', {
description: `Don't unzip the main payload`
})
.argv
const run = async() => {
if (argv._[0] === 'create') {
// powfile create -i example/floppy.png -o floppy-with-data.png example/*
const png = await create({ image: argv.image, files: argv._.slice(1) })
fs.writeFile(argv.output, png)
} else if (argv._[0] === 'extract') {
// powfile extract floppy-with-data.png -d test-extract
// or
// powfile extract floppy-with-data.png -d test-extract --no-unzip
extract({ image: argv.inputpng, dir: argv.dir, unzip: argv.unzip })
}
}
run()