<commit_before><?php
include(dirname(__FILE__).'/../lib/Service.php');

define('PROMPT', '> ');
$api = null;
$options = array(
	'service' => 'http://dev.rubrix.local/',
	'extra' => 'v2',
	'debug' => 0,
	'log' => 'req'
);

// Run a simple Presto shell
function shellinate() {
	print PROMPT;
	
    while ($cmd = fgets(STDIN)) {
    	global $options;
    	global $api;
    	$service = '';

    	
		$cmd = strtok(trim($cmd), ' ');
		$method = strtok(' ');
		$value = strtok('');
    		
		switch ($cmd) {
			case 'help': 
				show_help();
			break;
			
			case 'show':
				print "\n";
				if (in_array($method, array('', '*', 'all')) || !array_key_exists($method, $options))
					foreach ($options as $k => $v) { print "\t$k :\t $v\n"; }
				else
					print "$method = $options[$method]\n";
					
				print "\n";
			break;
			
			case 'set':
				if (strlen($method)) {
					$options[$method] = $value;
					print "Set $method to $value\n";
				}
			break;
			
			case 'get':
			case 'post':
			case 'put':
			case 'delete':
			case 'options':
			case 'head':
			
				try {
					
					if (!isset($api)) $api = new Service( $options );
					
					$pairs = explode(',', $value);
					foreach ($pairs as $v) {
						$p = explode('=', $v);
						if (count($p) == 2) $params[$p[0]] = $p[1]; 
						else $params[] = $p;
					}
					
					$call = "{$cmd}_{$method}";
					print_r($api->$call($params));
					print "\n";
				
				} catch (Exception $e) {
					print $e->getCode() . " : " . $e->getMessage() . "\n";
				}
				
				
			break;
			
			default:
				print "Not sure how to '$cmd'.\n";
			
			
		}
		print PROMPT;			
    }
}
function show_help() {
?>

Commands<commit_msg>Added command logging.<commit_after><?php
include(dirname(__FILE__).'/../lib/Service.php');

define('PROMPT', '> ');
$api = null;
$options = array(
	'service' => 'http://dev.rubrix.local/',
	'extra' => 'v2',
	'debug' => 0,
	'log' => 'req'
);



// Run a simple Presto shell
function shellinate() {
	print PROMPT;
	
    while ($cmd = fgets(STDIN)) {
    	global $options;
    	global $api;
    	$service = '';

    	$line = $cmd;
    	
    	$history = fopen('hist.log', "a+");
    	fwrite($history, $line);
    	fclose($history);
    	
		$cmd = strtok(trim($cmd), ' ');
		$method = strtok(' ');
		$value = strtok('');
    		
		switch ($cmd) {
			case 'help': 
				show_help();
			break;
			
			case 'show':
				print "\n";
				if (in_array($method, array('', '*', 'all')) || !array_key_exists($method, $options))
					foreach ($options as $k => $v) { print "\t$k :\t $v\n"; }
				else
					print "$method = $options[$method]\n";
					
				print "\n";
			break;
			
			case 'set':
				if (strlen($method)) {
					$options[$method] = $value;
					print "Set $method to $value\n";
				}
			break;
			
			case 'get':
			case 'post':
			case 'put':
			case 'delete':
			case 'options':
			case 'head':
			
				try {
					
					if (!isset($api)) $api = new Service( $options );
					
					$params = array();
					$pairs = explode(',', $value);
					foreach ($pairs as $v) {
						$p = explode('=', $v);
						if (count($p) == 2) $params[$p[0]] = $p[1]; 
						else $params[] = $p;
					}
					
					$call = "{$cmd}_{$method}";
					$data = $api->$call($params);
					print_r($data);
					print "\n";
				
				} catch (Exception $e) {
					print $e->getCode() . " : " . $e->getMessage() . "\n";
				}
				
				
			break;
			
			default:
				print "Not sure how to '$cmd'.\n";
			
			
		}
		print PROMPT;			
    }
}
function show_help() {
?>

Commands
{'fraction_non_alphanumeric': 0.21823361823361823, 'fraction_numerical': 0.002849002849002849, 'mean_word_length': 2.1659152389540126, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, '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': '2521205', 'n_tokens_mistral': 1704, 'n_tokens_neox': 1311, 'n_words': 301}