package org.oscii;

import org.apache.commons.cli.*;
import org.oscii.panlex.PanLexJSONParser;

import java.io.File;
import java.util.Arrays;
import java.util.regex.Pattern;

public class Main {

    public static void main(String[] args)
            throws java.io.IOException,
            java.lang.InterruptedException,
            ParseException {
        Options options = new Options();
        options.addOption("r", "read", true, "read JSON file");
        options.addOption("w", "write", true, "write JSON file");
        options.addOption("p", "panlex", true, "parse PanLex JSON");
        options.addOption("s", "serve", false, "listen on local rabbitmq");
        options.addOption("h", "host", true, "rabbitmq host");
        options.addOption("q", "queue", true, "rabbitmq queue");
        options.addOption("u", "username", true, "rabbitmq username");
        options.addOption("a", "password", true, "rabbitmq password");
        CommandLineParser parser = new BasicParser();
        CommandLine line = parser.parse( options, args );

        Lexicon lexicon = new Lexicon();

        if (line.hasOption("p")) {
            String path = line.getOptionValue("p");
            PanLexJSONParser panLex = new PanLexJSONParser(path);
            // TODO(denero) Add "languages" command-line option
            panLex.addLanguages(Arrays.asList("en", "es", "fr", "de"));
            panLex.read(null);
            panLex.yieldTranslations(lexicon::add);
        } else if (line.hasOption("r")) {
            lexicon.read(new File(line.getOptionValue("r")));
        }

        if (line.hasOption("w")) {
            lexicon.write(new File(line.getOptionValue("w")));
        }

        if (line.hasOption("s")) {
            String host = line.getOptionValue("h", "localhost");
            String queue = line.getOptionValue("q", "lexicon");
            String username = line.getOptionValue("u", "");
            String password = line.getOptionValue("a", "");
            RabbitHandler handler = new RabbitHandler(host, queue, username, password, lexicon);
            handler.ConnectAndListen();
        }
    }
}

@@ -135,16 +135,39 @@
 Arrays;%0A
+import java.util.List;%0A
 import j
@@ -190,16 +190,16 @@
 attern;%0A
-
 %0Apublic 
@@ -543,77 +543,8 @@
 %22);%0A
-        options.addOption(%22p%22, %22panlex%22, true, %22parse PanLex JSON%22);%0A
     
@@ -881,24 +881,232 @@
 password%22);%0A
+        options.addOption(%22p%22, %22panlex%22, true, %22parse PanLex JSON%22);%0A        options.addOption(%22pattern%22, true, %22expression pattern%22);%0A        options.addOption(%22l%22, %22languages%22, true, %22expression pattern%22);%0A
         Comm
@@ -1401,16 +1401,17 @@
 (path);%0A
+%0A
         
@@ -1418,132 +1418,450 @@
     
-// TODO(denero) Add %22languages%22 command-line option%0A            panLex.addLanguages(Arrays.asList(%22en%22, %22es%22, %22fr%22, %22de
+List%3CString%3E languages = Arrays.asList(%22en%22, %22es%22, %22fr%22, %22de%22);%0A            if (line.hasOption(%22l%22)) %7B%0A                languages = Arrays.asList(line.getOptionValue(%22l%22).split(%22 %22));%0A            %7D%0A            panLex.addLanguages(languages);%0A%0A            Pattern pattern = Pattern.compile(%22(?U)%5C%5Cp%7BLower%7D*%22);%0A            if (line.hasOption(%22pattern%22)) %7B%0A                pattern = Pattern.compile(line.getOptionValue(%22pattern
 %22));%0A
+            %7D%0A
     
@@ -1884,15 +1884,19 @@
 ead(
-null
+pattern
 );%0A
+%0A
     

limit to lowercase