<commit_before>package se.cs.casualmap.console;

import org.apache.commons.cli.*;
import se.cs.casualmap.api.io.MapFileWriter;
import se.cs.casualmap.api.io.MapWriter;
import se.cs.casualmap.api.map.Map;
import se.cs.casualmap.generator.Args;
import se.cs.casualmap.generator.MapGenerator;

import java.io.File;
import java.io.IOException;
import java.util.Optional;

/**
 * Created by indifferent on 8/6/15.
 */
public class Main {

    public static void main(String[] args) throws ParseException, IOException {
        Options options = new Options();
        options.addOption("f", true, "output map to file");
        options.addOption("size", true, "size of map in format width[,height]. If the latter is omitted both will be set to the provided value.");
        options.addOption("areaWidth", true, "the width of areas in the map in format min[,max]. If the latter is omitted both will be set to the provided value.");
        options.addOption("areaHeight", true, "the height of areas in the map in format min[,max]. If the latter is omitted both will be set to the provided value.");

        CommandLineParser parser = new DefaultParser();
        CommandLine cmd = parser.parse(options, args);

        Map map = generate(cmd);
        if (cmd.hasOption("f") && cmd.getOptionValue("f") != null) {
            MapFileWriter.forMap(map).write(new File(cmd.getOptionValue("f")));
        } else {
            MapWriter.forMap(map).write(System.out);
        }
    }

    /**
     * The map generation should be a bit more flexible..
     * @return a generated map
     */
    private static Map generate(CommandLine cmd) {

        Args.Builder argsBuilder = Args.newBuilder();

        Optional<String[]> size = getRangeValue(cmd, "size");
        if (size.isPresent()) {
            if (size.get().length > 1) {
                argsBuilder<commit_msg>some exception handling in main<commit_after>package se.cs.casualmap.console;

import org.apache.commons.cli.*;
import se.cs.casualmap.api.io.MapFileWriter;
import se.cs.casualmap.api.io.MapWriter;
import se.cs.casualmap.api.map.Map;
import se.cs.casualmap.generator.Args;
import se.cs.casualmap.generator.MapGenerator;

import java.io.File;
import java.io.IOException;
import java.util.Optional;

public class Main {

    public static void main(String[] args) throws ParseException, IOException {
        Options options = new Options();
        options.addOption("f", true, "output map to file");
        options.addOption("size", true, "size of map in format width[,height]. If the latter is omitted both will be set to the provided value.");
        options.addOption("areaWidth", true, "the width of areas in the map in format min[,max]. If the latter is omitted both will be set to the provided value.");
        options.addOption("areaHeight", true, "the height of areas in the map in format min[,max]. If the latter is omitted both will be set to the provided value.");

        CommandLineParser parser = new DefaultParser();

        try {
            CommandLine cmd = parser.parse(options, args);

            Map map = generate(cmd);

            if (cmd.hasOption("f") && cmd.getOptionValue("f") != null) {
                MapFileWriter.forMap(map).write(new File(cmd.getOptionValue("f")));
            } else {
                MapWriter.forMap(map).write(System.out);
            }
        } catch (Exception e) {
            System.out.println("Oops: " + e.getMessage());
        }
    }

    /**
     * The map generation should be a bit more flexible..
     * @return a generated map
     */
    private static Map generate(CommandLine cmd) {

        Args.Builder argsBuilder = Args.newBuilder();

        Optional<String[]> size = getRangeValue(cmd, "size");
        if (size.isPresent()) {
            if (size.get().length > 1) {
                argsBuilder
{'fraction_non_alphanumeric': 0.11998958875585633, 'fraction_numerical': 0.0015616866215512754, 'mean_word_length': 2.8238805970149254, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '4044784', 'n_tokens_mistral': 1097, 'n_tokens_neox': 1066, 'n_words': 338}