<commit_before>package com.xafero.vee.cmd;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.StringWriter;

import javax.script.Bindings;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineFactory;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;

import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;

import com.google.common.base.MoreObjects;
import com.xafero.vee.env.Console;
import com.xafero.vee.env.Environment;
import com.xafero.vee.env.FileSystem;
import com.xafero.vee.env.Media;
import com.xafero.vee.env.Time;
import com.xafero.vee.env.Window;
import com.xafero.vee.env.storage.LocalStorage;
import com.xafero.vee.env.storage.SessionStorage;
import com.xafero.vee.util.Files;
import com.xafero.vee.util.Strings;

public class MainApp {

	private static final String APP_SHORT_NAME = "vee";
	private static final String APP_VER = "0.1-alpha";
	private static final String APP_SRC_URL = "https://github.com/xafero/vee";

	public static void main(String[] args) {
		// Define options
		Option help = new Option("?", "help", false, "print this message");
		Option version = new Option("v", "version", false, "print the version information and exit");
		Option eval = Option.builder("e").desc("evaluate script").argName("file").longOpt("eval").hasArg().build();
		Option list = new Option("l", "list", false, "print all available languages");
		// Collect them
		Options options = new Options();
		options.addOption(help);
		options.addOption(version);
		options.addOption(eval);
		options.addOption(list);
		// If nothing given, nothing will happen
		if (args == null || args.length < 1) {
			printHelp(options);
			return;
		}
		// Parse command line
		try {
			CommandLineParser parser = new DefaultParser();
			CommandLine line = parser.parse(options, args);
			// Work on it
			process(line, options);
		} catch (Throwable e) {
			System.err.printf("Error occurred: %n " + e.getMessage());
		}
	}

	private static void process(CommandLine line, Options options) throws ScriptException, IOException {
		if (line.hasOption('?')) {
			printHelp(options);
			return;
		}
		if (line.hasOption('v')) {
			printVersion();
			return;
		}
		if (line.hasOption('l')) {
			printLanguages();
			return;
		}
		if (line.hasOption('e')) {
			execute(line.getOptionValue('e'));
			return;
		}
		throw new UnsupportedOperationException("Unrecognized option: " + line.getArgList());
	}

	private static void printHelp(Options options) {
		String header = String.format("Ubiquitous scripting in an extensible environment%n%n");
		String footer = String.format("%nPlease report issues at " + APP_SRC_URL);
		HelpFormatter formatter = new HelpFormatter();
		formatter.printHelp(APP_SHORT_NAME, header, options, footer, true);
	}

	private static void printVersion() throws IOException {
		StringWriter writer;
		BufferedWriter out = new BufferedWriter(writer = new StringWriter());
		out.write(APP_SHORT_NAME + " " + APP_VER + " built on JSR 223.");
		out.newLine();
		out.newLine();
		out.write("Copyright (C) 2015 xafero");
		out.newLine();
		out.write("License AGPLv3+: GNU AGPL version 3 or later");
		out.newLine();<commit_msg>Additional languages will now be pre-loaded if given<commit_after>package com.xafero.vee.cmd;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.StringWriter;
import java.net.URI;

import javax.script.Bindings;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineFactory;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;

import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;

import com.google.common.base.MoreObjects;
import com.xafero.vee.cfg.Configuration;
import com.xafero.vee.cfg.Language;
import com.xafero.vee.env.Console;
import com.xafero.vee.env.Environment;
import com.xafero.vee.env.FileSystem;
import com.xafero.vee.env.Media;
import com.xafero.vee.env.Time;
import com.xafero.vee.env.Window;
import com.xafero.vee.env.storage.LocalStorage;
import com.xafero.vee.env.storage.SessionStorage;
import com.xafero.vee.util.Files;
import com.xafero.vee.util.Strings;

public class MainApp {

	private static final String APP_SHORT_NAME = "vee";
	private static final String APP_VER = "0.1-alpha";
	private static final String APP_SRC_URL = "https://github.com/xafero/vee";

	public static void main(String[] args) {
		// Define options
		Option help = new Option("?", "help", false, "print this message");
		Option version = new Option("v", "version", false, "print the version information and exit");
		Option eval = Option.builder("e").desc("evaluate script").argName("file").longOpt("eval").hasArg().build();
		Option list = new Option("l", "list", false, "print all available languages");
		// Collect them
		Options options = new Options();
		options.addOption(help);
		options.addOption(version);
		options.addOption(eval);
		options.addOption(list);
		// If nothing given, nothing will happen
		if (args == null || args.length < 1) {
			printHelp(options);
			return;
		}
		// Parse command line
		try {
			CommandLineParser parser = new DefaultParser();
			CommandLine line = parser.parse(options, args);
			// Work on it
			process(line, options);
		} catch (Throwable e) {
			System.err.printf("Error occurred: %n " + e.getMessage());
		}
	}

	private static void process(CommandLine line, Options options) throws ScriptException, IOException {
		if (line.hasOption('?')) {
			printHelp(options);
			return;
		}
		if (line.hasOption('v')) {
			printVersion();
			return;
		}
		if (line.hasOption('l')) {
			processConfig();
			printLanguages();
			return;
		}
		if (line.hasOption('e')) {
			processConfig();
			execute(line.getOptionValue('e'));
			return;
		}
		throw new UnsupportedOperationException("Unrecognized option: " + line.getArgList());
	}

	private static void processConfig() {
		Configuration cfg = Configuration.from(null);
		for (Language lang : cfg.getLanguages()) {
			URI uri = lang.getRequire();
			Environment env = new Environment();
			try {
				env.require(uri);
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
	}

	private static void printHelp(Options options) {
		String header = String.format("Ubiquitous scripting in an extensible environment%n%n");
		String footer = String.format("%nPlease report issues at " + APP_SRC_URL);
		HelpFormatter formatter = new HelpFormatter();
		formatter.printHelp(APP_SHORT_NAME, header, options, footer, true);
	}

	private static void printVersion() throws IOException {
		StringWriter writer;
		BufferedWriter out = new BufferedWriter(writer = new StringWriter());
		out.write(APP_SHORT_NAME + " " + APP_VER + " built on JSR 223.");
		out.newLine();
		out.newLine();
		out.write("Copyright (C) 2015 xafero");
		out.newLine();
		out.write("License AGPLv3+: GNU AGPL version 3 or later");
		out.newLine();
{'fraction_non_alphanumeric': 0.13212608987256874, 'fraction_numerical': 0.0032193158953722333, 'mean_word_length': 4.627169811320755, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '523422', 'n_tokens_mistral': 2526, 'n_tokens_neox': 2304, 'n_words': 568}