diff --git a/src/index.js b/src/index.js old mode 100644 new mode 100755 index 9ac52f9..fcb86c4 --- a/src/index.js +++ b/src/index.js @@ -10,13 +10,20 @@ const program = require('commander'); const encrypt = () => { co(function *() { - let data = yield prompt(chalk.yellow('Enter data: ')); - let password = yield prompt.password(chalk.yellow('Enter password: ')); - let confirmPassword = yield prompt.password(chalk.yellow('Confirm password: ')); + let data = program.data + if (!data) { + data = yield prompt(chalk.yellow('Enter data: ')); + } - if (password !== confirmPassword) { - console.error(chalk.red('\nPasswords do not match. Please try again.')); - process.exit(1); + let password = program.password + if (!password) { + password = yield prompt.password(chalk.yellow('Enter password: ')); + let confirmPassword = yield prompt.password(chalk.yellow('Confirm password: ')); + + if (password !== confirmPassword) { + console.error(chalk.red('\nPasswords do not match. Please try again.')); + process.exit(1); + } } const encryptedData = sjcl.encrypt(password, data); @@ -26,14 +33,26 @@ const encrypt = () => { console.error(chalk.red('\nThere we an error encrypting the data. Please try again')); process.exit(1); } - console.log(chalk.green('Encrypted data:\n\t\t %s'), encryptedData); + + if (program.quite) { + console.log(encryptedData); + } else { + console.log(chalk.green('Encrypted data:\n\t\t %s'), encryptedData); + } }) } const decrypt = () => { co(function *() { - let encryptedData = yield prompt(chalk.yellow('Enter encrypted data: ')); - let password = yield prompt.password(chalk.yellow('Enter password: ')); + let encryptedData = program.data + if (!encryptedData) { + encryptedData = yield prompt(chalk.yellow('Enter encrypted data: ')); + } + + let password = program.password + if (!password) { + password = yield prompt.password(chalk.yellow('Enter password: ')); + } let decryptedData; @@ -44,10 +63,18 @@ const decrypt = () => { process.exit(1); } - console.log(chalk.green('Decrypted data:\n\t\t %s'), decryptedData); + if (program.quite) { + console.log(decryptedData) + } else { + console.log(chalk.green('Decrypted data:\n\t\t %s'), decryptedData); + } }) } +program.option('-q, --quite', 'quiet (non-verbose) output') +program.option('-d, --data ', 'data to encrypt/decrypt') +program.option('-p, --password ', 'password to use for encryption/decryption') + program.command('encrypt') .description('encrypt raw data')