#!/usr/bin/env node
var cli = require('../cli')
, path = require('path')
var program = require('commander')
.version(require('../package.json').version)
.option('-w, --wallet
', 'wallet location (default: ~/.salty)', path.join(process.env.HOME, '.salty'))
.option('-F, --force', 'do it anyway')
program
.command('init')
.description('initialize or update a wallet')
.option('-R, --regen', 'regenerate decryption key')
.action(cli.init)
program
.command('id')
.description('output your shareable pubkey string')
.alias('pubkey')
.action(cli.id)
program
.command('import ')
.alias('i')
.description('import a pubkey')
.action(cli.import)
program
.command('ls')
.alias('l')
.description('list imported keys')
.action(cli.ls)
program
.command('rm ')
.description('remove pubkey')
.action(cli.rm)
program
.command('encrypt [infile|indir] [outfile]')
.alias('e')
.description('encrypt a file')
.option('-t, --to ', 'email address to encrypt for. (must be imported first. default: self)')
.option('-m, --message', 'compose a message instead of using [infile] (implies -a)')
.option('-s, --sign', 'sign the message to reveal/prove our identity')
.option('-H, --header ', 'add a custom header (repeatable)')
.option('-a, --armor', 'output ASCII armor to STDOUT')
.option('-g, --gist', 'upload encrypted result as a gist')
.option('-F, --force', 'ignore warnings and do it')
.option('--no-translate', 'output raw header')
.option('-D, --delete', 'delete the original file after encryption')
.action(cli.encrypt)
program
.command('decrypt [outfile]')
.alias('d')
.description('decrypt and verify a file')
.option('-s, --sig', 'require a signature')
.option('-a, --armor', 'expect ASCII armor, output to STDOUT')
.option('-g, --gist', 'download the encrypted input from a gist')
.option('-F, --force', 'ignore warnings and do it')
.option('--no-translate', 'output raw header')
.option('-D, --delete', 'delete the salty file after verification')
.action(cli.decrypt)
program
.command('sign [outfile]')
.alias('s')
.description('create a signature')
.option('-H, --header ', 'add a custom header (repeatable)')
.option('-h, --hash ', 'hash algorithm (default: sha256)', String, 'sha256')
.option('-a, --armor', 'output ASCII armor to STDOUT')
.option('--no-translate', 'output raw header')
.option('-F, --force', 'ignore warnings and do it')
.action(cli.sign)
program
.command('verify [infile]')
.alias('v')
.option('-a, --armor', 'expect ASCII armor, output to STDOUT')
.option('--no-translate', 'output raw header')
.description('verify a signature')
.action(cli.verify)
program
.command('save [indir] [outfile]')
.description('save an encrypted backup of your wallet')
.action(cli.save)
program
.command('restore [infile] [outdir]')
.description('restore your wallet from a backup')
.action(cli.restore)
program
.command('encode [infile]')
.description('output base58-encoded data to STDOUT')
.action(cli.encode)
program
.command('decode [infile]')
.description('output base58-decoded data to STDOUT')
.action(cli.decode)
program
.command('*')
.action(function (infile) {
program.outputHelp()
process.exit(1)
})
program.parse(process.argv)
if (!program.rawArgs[2]) {
program.outputHelp()
process.exit(1)
}