<commit_before>#!/usr/bin/env node

var _ = require('lodash');
var async = require('async');

var utils = require('../../utils');

var actions = utils.getActions();

function registerCommand(program) {
	program
		.command('role [quantity]')
		.alias('r')
		.description('Adds one or more roles to the database.')
		.option('-t, --type <type>', 'Type of role to add. Accepts "site" or "organization". Defaults to "regular".')
		.action(function(number) {
			var type = this.type;

			number = !_.isNaN(Number(number)) ? Number(number) : 1;

			if (type === 'site') {
				type = 2;
			}
			else if (type === 'organization' || type === 'org') {
				type = 3;
			}
			else {
				type = 1;
			}

			addRole(number, type);
		});

	return program;
}

function addRole(numberOfRoles, type, callback) {
	var roles = [];
	var bar = utils.getProgressBar(numberOfRoles);

	async.timesSeries(
		numberOfRoles,
		function(n, asyncCallback) {
			var name = utils.generateRoleName(type);

			actions.addRole(
				name,
				type,
				function(error, response) {
					if (!error) {
						bar.tick();
						asyncCallback(null, response);
					}
				}
			);
		},
		function(error, results) {
			if (!error) {
				for (var i = 0, length = results.length; i < length; i++) {
					console.log('');
					console.log('New Role:');
					utils.printJSON(JSON.parse(results[i]));
					console.log('');
				}

				console.log('Successfully added', + results.length + ' new roles.');

				if (callback) {
					callback(null, results);
				}
			}
		}
	);

	return roles;
}<commit_msg>Add role command only logs through callback<commit_after>#!/usr/bin/env node

var _ = require('lodash');
var async = require('async');

var utils = require('../../utils');

var actions = utils.getActions();

function registerCommand(program) {
	program
		.command('role [quantity]')
		.alias('r')
		.description('Adds one or more roles to the database.')
		.option('-t, --type <type>', 'Type of role to add. Accepts "site" or "organization". Defaults to "regular".')
		.action(function(number) {
			var type = this.type;

			number = !_.isNaN(Number(number)) ? Number(number) : 1;

			if (type === 'site') {
				type = 2;
			}
			else if (type === 'organization' || type === 'org') {
				type = 3;
			}
			else {
				type = 1;
			}

			addRole(number, type, function(err, results) {
				for (var i = 0, length = results.length; i < length; i++) {
					console.log('');
					console.log('New Role:');
					utils.printJSON(JSON.parse(results[i]));
					console.log('');
				}

				console.log('Successfully added', + results.length + ' new roles.');
			});
		});

	return program;
}

function addRole(numberOfRoles, type, callback) {
	var roles = [];
	var bar = utils.getProgressBar(numberOfRoles);

	async.timesSeries(
		numberOfRoles,
		function(n, asyncCallback) {
			var name = utils.generateRoleName(type);

			actions.addRole(
				name,
				type,
				function(error, response) {
					if (!error) {
						bar.tick();
						asyncCallback(null, response);
					}
				}
			);
		},
		function(error, results) {
			if (!error && callback) {
				callback(null, results);
			}
		}
	);

	return roles;
}
{'fraction_non_alphanumeric': 0.17327832434147888, 'fraction_numerical': 0.0031735956839098697, 'mean_word_length': 2.9697732997481108, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5736774', 'n_tokens_mistral': 1303, 'n_tokens_neox': 1057, 'n_words': 257}