<commit_before>
function cmdConf(cmd){
	var that = this;
	that.cmd = cmd.slice(0);
	that.cmdStr = cmd.concat();
	that.conf = {key: {}, shortKey: {}};
	that.regexp = /^(-{1,2})([a-zA-Z]+)$/;
	
	that.args = cmd.slice(2);
	that.processed = false;
	that.parameters = {arguments: []};

	
	
	/**
	 * Configure the command analyser.
	 */
	that.configure = function(conf){
		for(var name in conf){
			var values = conf[name];
			
			values.name = name;
			values.key = values.key ? values.key : name;
			
			that.conf.key[values.key] = values;
			if(values.shortKey)	that.conf.shortKey[values.shortKey] = values;
			
			
		}
	}
	
	that.getParameters = function(){
		if(!that.processed) process();
		
		return that.parameters;
	}
	
	function process(){
		var args = that.args.slice(0);
		for(var i in args){
			var arg = args[i];
			if(that.regexp.test(arg)){
				var catchWord = RegExp.$2;
				switch(RegExp.$1){
					case '-': 
						processShortKey(catchWord, i, args);
						break;
					case '--':
						processKey(catchWord, i, args);
						break;
				}
			} else {
				addArgument(arg);
			}
		}
		that.processed = true
	}
	
	function processKey(word, position, args){
		var option = that.conf.key[word];
		if(!option) return;
		
		option.position = parseInt(position);
		processOption(option, args);
	}
	
	function processShortKey(word, position, args){
		var option = that.conf.shortKey[word];
		if(!option) return;
		
		option.position = parseInt(position);
		processOption(option, args);
	}
	
	function processOption(option, args){
		var name = option.name;
		var action = option.action;
		switch(action){
			case 'get':
				var params = getCmdParam(option.position+1, option.number, args);
				setParam(name,params);
				break;
			case 'set':
				var value = (option.value) ? option.value : undefined;
				setParam(name,value);
				break;
			default:
				break;
		}
	}
	
	function getCmdParam(start, num, args){
		var params = args.splice(start,num);
		return num == 1 ? params[0] : params;
	}
	
	function setParam(key, value){
		that.parameters[key] = value;
	}
	
	function addArgument(value){
		that.parameters.arguments.push(value);
	}
}

module.exports = new cmdConf(process.argv);<commit_msg>Encapsulate properties of module.<commit_after>/*
 * This file is part of Node-CMD-Conf.
 * 
 * Node-CMD-Conf is distributed under the terms of the 
 * GNU General Public License version 3.0.
 * 
 * Node-CMD-Conf is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */


function cmdConf(cmd){
	var that = this;
	var command = {
		itemList: cmd.slice(0),
		cmdStr: '',
		args: cmd.slice(2)
	};
	var conf = {
		processed: false,
		regexp: /^(-{1,2})([a-zA-Z]+)$/,
		key: {},
		shortKey: {}
	};
	var parameters = {arguments: []};
	
	command.cmdStr = command.itemList.concat();

	
	
	/**
	 * Configure the command analyser.
	 */
	that.configure = function(config){
		
		for(var name in config){
			var values = config[name];
			
			values.name = name;
			values.key = values.key ? values.key : name;
			
			conf.key[values.key] = values;
			if(values.shortKey)	conf.shortKey[values.shortKey] = values;
			
			conf.processed = false;
			parameters = {arguments: []};
		}
		
	};
	
	that.getParameters = function(){
		if(!conf.processed) process();
		
		return parameters;
	};
	
	function process(){
		var args = command.args.slice(0);
		for(var i in args){
			var arg = args[i];
			if(conf.regexp.test(arg)){
				var catchWord = RegExp.$2;
				switch(RegExp.$1){
					case '-': 
						processShortKey(catchWord, i, args);
						break;
					case '--':
						processKey(catchWord, i, args);
						break;
				}
			} else {
				addArgument(arg);
			}
		}
		conf.processed = true
	}
	
	function processKey(word, position, args){
		var option = conf.key[word];
		if(!option) return;
		
		option.position = parseInt(position);
		processOption(option, args);
	}
	
	function processShortKey(word, position, args){
		var option = conf.shortKey[word];
		if(!option) return;
		
		option.position = parseInt(position);
		processOption(option, args);
	}
	
	function processOption(option, args){
		var name = option.name;
		var action = option.action;
		switch(action){
			case 'get':
				var params = getCmdParam(option.position+1, option.number, args);
				setParam(name,params);
				break;
			case 'set':
				var value = (option.value) ? option.value : undefined;
				setParam(name,value);
				break;
			default:
				break;
		}
	}
	
	function getCmdParam(start, num, args){
		var params = args.splice(start,num);
		return num == 1 ? params[0] : params;
	}
	
	function setParam(key, value){
		parameters[key] = value;
	}
	
	function addArgument(value){
		parameters.arguments.push(value);
	}
}

module.exports = new cmdConf(process.argv);
{'fraction_non_alphanumeric': 0.1453788179293931, 'fraction_numerical': 0.00436334787782626, 'mean_word_length': 3.154036243822076, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, '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': '5333420', 'n_tokens_mistral': 2001, 'n_tokens_neox': 1666, 'n_words': 410}