<commit_before>package org.devocative.ares.service.command.dsl;

import groovy.lang.Closure;
import org.devocative.adroit.CalendarUtil;
import org.devocative.ares.cmd.CommandCenter;
import org.devocative.ares.cmd.CommandException;
import org.devocative.ares.cmd.SshResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.*;

public class MainCommandDSL {
	private static final Logger logger = LoggerFactory.getLogger(MainCommandDSL.class);

	private static final List<String> VALID_SSH_PROPERTIES = Arrays.asList("prompt", "cmd", "force", "stdin", "result");
	private static final List<String> VALID_DB_PROPERTIES = Arrays.asList("prompt", "query", "params", "filters", "result");

	private CommandCenter commandCenter;

	// ------------------------------

	public MainCommandDSL(CommandCenter commandCenter) {
		this.commandCenter = commandCenter;
	}

	// ------------------------------

	public Object ssh(Closure closure) {
		MapOfClosureDelegate delegate = new MapOfClosureDelegate();
		Closure rehydrate = closure.rehydrate(delegate, commandCenter.getParams(), null);
		rehydrate.setResolveStrategy(Closure.DELEGATE_FIRST);
		rehydrate.call();
		Map<String, Object> clsAsMap = delegate.getClosureAsMap();

		for (String key : clsAsMap.keySet()) {
			if (!VALID_SSH_PROPERTIES.contains(key)) {
				throw new CommandException("Invalid property for ssh{}: " + key);
			}
		}

		String prompt = clsAsMap.containsKey("prompt") ? clsAsMap.get("prompt").toString() : null;
		String cmd = clsAsMap.containsKey("cmd") ? clsAsMap.get("cmd").toString() : null;
		Boolean force = clsAsMap.containsKey("force") ? (Boolean) clsAsMap.get("force") : null;
		String[] stdin = clsAsMap.containsKey("stdin") ? (String[]) clsAsMap.get("stdin") : null;
		SshResult sshResult = commandCenter.ssh(prompt, cmd, force, stdin);
		if (clsAsMap.containsKey("result")) {
			Closure result = (Closure) clsAsMap.get("result");
			return result.call(sshResult);
		} else {
			return sshResult;
		}
	}

	public Object db(Closure closure) {
		MapOfClosureDelegate delegate = new MapOfClosureDelegate();
		Closure rehydrate = closure.rehydrate(delegate, commandCenter.getParams(), null);
		rehydrate.setResolveStrategy(Closure.DELEGATE_FIRST);
		rehydrate.call();
		Map<String, Object> clsAsMap = delegate.getClosureAsMap();

		for (String key : clsAsMap.keySet()) {
			if (!VALID_DB_PROPERTIES.contains(key)) {
				throw new CommandException("Invalid property for db{}: " + key);
			}
		}

		String prompt = clsAsMap.containsKey("prompt") ? clsAsMap.get("prompt").toString() : null;
		String query = clsAsMap.containsKey("query") ? clsAsMap.get("query").toString() : null;
		Map<String, Object> params = clsAsMap.containsKey("params") ? (Map<String, Object>) clsAsMap.get("params") : null;
		Map<String, Object> filters = clsAsMap.containsKey("filters") ? (Map<String, Object>) clsAsMap.get("filters") : null;
		Object queryResult = commandCenter.sql(prompt, query, params, filters);
		if (clsAsMap.containsKey("result")) {
			Closure result = (Closure) clsAsMap.get("result");
			return result.call(queryResult);
		} else {
			return queryResult;
		}
	}

	// ---------------

	public Map<CharSequence, Object> $inputs(CharSequence... params) {
		Map<String, Object> inParams = commandCenter.getParams();

		Map<CharSequence, Object> result = new HashMap<>();
		for (CharSequence param : params) {
			if (inParams.containsKey(param.toString())) {
				result.put(param, inParams.get(param.toString()));
			}
		}
		return result;
	}

	public void $userPasswordUpdated(CharSequence username, CharSequence password) {
		commandCenter.userPasswordUpdated(username.toString(), password.toString());
	}

	public void $checkVMServers(List<Map<String, String>> servers) {
		commandCenter.checkVMServers(servers);
	}

	public void $error(CharSequence message) {
		commandCenter.error(message.toString());
	}

	public String $now() {
		return $now("yyyyMMdd_HHmmss");
	}

	public String $now(CharSequence format) {
		return CalendarUtil.formatDate(new Date(), format.toString());
	}

	public void $log(CharSequence log) {
		logger.debug(log.toString());
	}

	// other

	public CommandCenter getCommandCenter() {
		return commandCenter;
	}
}
<commit_msg>DeBug: stdin cast as string<commit_after>package org.devocative.ares.service.command.dsl;

import groovy.lang.Closure;
import org.devocative.adroit.CalendarUtil;
import org.devocative.ares.cmd.CommandCenter;
import org.devocative.ares.cmd.CommandException;
import org.devocative.ares.cmd.SshResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.*;

public class MainCommandDSL {
	private static final Logger logger = LoggerFactory.getLogger(MainCommandDSL.class);

	private static final List<String> VALID_SSH_PROPERTIES = Arrays.asList("prompt", "cmd", "force", "stdin", "result");
	private static final List<String> VALID_DB_PROPERTIES = Arrays.asList("prompt", "query", "params", "filters", "result");

	private CommandCenter commandCenter;

	// ------------------------------

	public MainCommandDSL(CommandCenter commandCenter) {
		this.commandCenter = commandCenter;
	}

	// ------------------------------

	public Object ssh(Closure closure) {
		MapOfClosureDelegate delegate = new MapOfClosureDelegate();
		Closure rehydrate = closure.rehydrate(delegate, commandCenter.getParams(), null);
		rehydrate.setResolveStrategy(Closure.DELEGATE_FIRST);
		rehydrate.call();
		Map<String, Object> clsAsMap = delegate.getClosureAsMap();

		for (String key : clsAsMap.keySet()) {
			if (!VALID_SSH_PROPERTIES.contains(key)) {
				throw new CommandException("Invalid property for ssh{}: " + key);
			}
		}

		String prompt = clsAsMap.containsKey("prompt") ? clsAsMap.get("prompt").toString() : null;
		String cmd = clsAsMap.containsKey("cmd") ? clsAsMap.get("cmd").toString() : null;
		Boolean force = clsAsMap.containsKey("force") ? (Boolean) clsAsMap.get("force") : null;
		String stdin = clsAsMap.containsKey("stdin") ? clsAsMap.get("stdin").toString() : null;
		SshResult sshResult = commandCenter.ssh(prompt, cmd, force, stdin);
		if (clsAsMap.containsKey("result")) {
			Closure result = (Closure) clsAsMap.get("result");
			return result.call(sshResult);
		} else {
			return sshResult;
		}
	}

	public Object db(Closure closure) {
		MapOfClosureDelegate delegate = new MapOfClosureDelegate();
		Closure rehydrate = closure.rehydrate(delegate, commandCenter.getParams(), null);
		rehydrate.setResolveStrategy(Closure.DELEGATE_FIRST);
		rehydrate.call();
		Map<String, Object> clsAsMap = delegate.getClosureAsMap();

		for (String key : clsAsMap.keySet()) {
			if (!VALID_DB_PROPERTIES.contains(key)) {
				throw new CommandException("Invalid property for db{}: " + key);
			}
		}

		String prompt = clsAsMap.containsKey("prompt") ? clsAsMap.get("prompt").toString() : null;
		String query = clsAsMap.containsKey("query") ? clsAsMap.get("query").toString() : null;
		Map<String, Object> params = clsAsMap.containsKey("params") ? (Map<String, Object>) clsAsMap.get("params") : null;
		Map<String, Object> filters = clsAsMap.containsKey("filters") ? (Map<String, Object>) clsAsMap.get("filters") : null;
		Object queryResult = commandCenter.sql(prompt, query, params, filters);
		if (clsAsMap.containsKey("result")) {
			Closure result = (Closure) clsAsMap.get("result");
			return result.call(queryResult);
		} else {
			return queryResult;
		}
	}

	// ---------------

	public Map<CharSequence, Object> $inputs(CharSequence... params) {
		Map<String, Object> inParams = commandCenter.getParams();

		Map<CharSequence, Object> result = new HashMap<>();
		for (CharSequence param : params) {
			if (inParams.containsKey(param.toString())) {
				result.put(param, inParams.get(param.toString()));
			}
		}
		return result;
	}

	public void $userPasswordUpdated(CharSequence username, CharSequence password) {
		commandCenter.userPasswordUpdated(username.toString(), password.toString());
	}

	public void $checkVMServers(List<Map<String, String>> servers) {
		commandCenter.checkVMServers(servers);
	}

	public void $error(CharSequence message) {
		commandCenter.error(message.toString());
	}

	public String $now() {
		return $now("yyyyMMdd_HHmmss");
	}

	public String $now(CharSequence format) {
		return CalendarUtil.formatDate(new Date(), format.toString());
	}

	public void $log(CharSequence log) {
		logger.debug(log.toString());
	}

	// other

	public CommandCenter getCommandCenter() {
		return commandCenter;
	}
}

{'fraction_non_alphanumeric': 0.1544983513895431, 'fraction_numerical': 0.0004710315591144607, 'mean_word_length': 4.765784114052953, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, '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': '2280478', 'n_tokens_mistral': 2915, 'n_tokens_neox': 2683, 'n_words': 539}