console.error(`\n${logSymbols.error} ${error.message}`); process.exit(1); });
/** * Shorthand helper to output a green message * * @param {string} message Message to output * * @method success * @public */ success(message) { return this.log(`${logSymbols.success} ${message}`); }
it('success outputs message with correct symbols', function (done) { const stdout = streamTestUtils.getWritableStream(function (output) { expect(output, 'output exists').to.be.ok; expect(output, 'output value').to.equal(`${logSymbols.success} test\n`); done(); }); stdout.on('error', done); const UI = require(modulePath); const ui = new UI({stdout: stdout}); ui.success('test'); });
yarg.command('open [file]', 'opens save file and returns data in the terminal', (yargs) => { yargs.positional('file', { type: 'string', describe: 'file to open' }) }, function(argv) { if(!argv) { console.log(`${logSymbols.warning} ${chalk.yellow('Please enter the name of the file you want to open')}`); } fs.access(`data/${argv.file}`, fs.F_OK, (err) => { if (err) throw err; fs.readFile(`data/${argv.file}`, 'utf8', (err1, data) => { if(err1) throw err1; let realdata = JSON.parse(data); for(let i = 0; i < realdata.array.length; i++) { let selected = realdata.array[i]; console.log(`${chalk.blue('ip:')} ${chalk.green(selected.ip)} ${chalk.blue('port:')} ${chalk.green(selected.port)} ${chalk.blue('success:')} ${selected.success == true ? chalk.green(selected.success) : chalk.red(selected.success)}`); } }) }); });
/** * Shorthand helper method to output a red message * * @param {string} message Message to output * * @method fail * @public */ fail(message) { return this.log(`${logSymbols.error} ${message}`); }
.catch((err) => { console.error( logSymbols.error, options.verbose ? err.stack : err.message );
if (err) reject(err); if (output.success == false) { console.log(`${logSymbols.error} ${chalk.blue('Port:')} ${chalk.green(portOptions.quickScanArray[i])} ${chalk.blue('IP:')} ${chalk.green(scannedip)}`); data.push(`{"success": false, "port": "${portOptions.quickScanArray[i]}", "ip": "${scannedip}"}`); resolve(); } else if (output.success == true) { console.log(`${logSymbols.success} ${chalk.blue('Port:')} ${chalk.green(portOptions.quickScanArray[i])} ${chalk.blue('IP:')} ${chalk.green(scannedip)}`); data.push(`{"success": true, "port": "${portOptions.quickScanArray[i]}", "ip": "${scannedip}"}`); resolve(); if (err) reject(err); if (output.success == false) { console.log(`${logSymbols.error} ${chalk.blue('Port:')} ${chalk.green(i)} ${chalk.blue('IP:')} ${chalk.green(scannedip)}`); data.push(`{success: false, port: ${i}, ip: ${scannedip}}`); resolve(); } else if (output.success == true) { console.log(`${logSymbols.success} ${chalk.blue('Port:')} ${chalk.green(i)} ${chalk.blue('IP:')} ${chalk.green(scannedip)}`); data.push(`{"success": true, "port": "${i}", "ip": "${scannedip}"}`); resolve(); console.log(`${logSymbols.warning} ${chalk.yellow('Please either provide the first, last or both range numbers')}`); } else if (argv.options == 'r' && argv.rangeFN <= 0 || argv.rangeSN > 65535) { console.log(`${logSymbols.warning} ${chalk.yellow('The first range number must be greater than 1 and the second number must be less than 65535')}`); } else { console.log(`${logSymbols.warning} ${chalk.yellow('Please give a valid scan type')}`)
yarg.command('save [name]', 'saves previous scan permanently', (yargs) => { yargs.positional('name', { type: 'string', describe: 'name of the file in which your scan will be saved' }) }, function(argv) { if(!argv) { console.log(`${logSymbols.warning} ${chalk.yellow('Please enter the name for the file of the scan you want to save')}`); } fs.access('data/temporary.json', fs.F_OK, (err) => { if (err) throw err; fs.readFile('data/temporary.json', 'utf8', (err1, data) => { if (err1) throw err1; let realdata = JSON.parse(data); for(let i = 0; i < realdata.array.length; i++) { fs.writeFile(`data/${argv.name}.json`, realdata.array[i], (err2) => { if (err2) throw err2; console.log(`${chalk.blue('Your scan has been permanently saved in file:')} ${chalk.green(`${argv.name}.json`)}`) }); } }); }) });
it('fail outputs message with correct formatting', function (done) { const stdout = streamTestUtils.getWritableStream(function (output) { expect(output, 'output exists').to.be.ok; expect(output, 'output value').to.equal(`${logSymbols.error} test\n`); done(); }); stdout.on('error', done); const UI = require(modulePath); const ui = new UI({stdout: stdout}); ui.fail('test'); });