/*******************************************************************************
 * OulipoMachine licenses this file to you under the Apache License, Version 2.0
 * (the "License");  you may not use this file except in compliance with the License.  
 *
 * You may obtain a copy of the License at
 *   
 *       http://www.apache.org/licenses/LICENSE-2.0
 *    
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License. See the NOTICE file distributed with this work for 
 * additional information regarding copyright ownership. 
 *******************************************************************************/
package org.oulipo.machine.server;

import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.OptionBuilder;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.cli.PosixParser;

public class Main {

	private static Options addOptions() {
        Options options = new Options();
        Option helpOption = Option.builder("h").longOpt("help")
                .desc("Display help").build();
        Option databaseOption = Option.builder("db").longOpt("databaseDir")
                .desc("Directory of database").build();
        Option portOption = Option.builder("p").longOpt("port")
                .desc("Server port").build();
        
        OptionBuilder.withLongOpt("summary");
		OptionBuilder
                .withDescription("Output as summary statics");
		Option summaryOption = OptionBuilder
                .create("s");
        OptionBuilder.withLongOpt("output");
		OptionBuilder
                .withDescription("Log output file");
		Option outputOption = OptionBuilder
                .create("o");
        OptionBuilder.withLongOpt("raw");
		OptionBuilder
                .withDescription("Output as raw delimited format");
		Option rawOption = OptionBuilder
                .create("r");

        
        OptionBuilder.hasOptionalArg();
		OptionBuilder.withLongOpt("config");
		OptionBuilder
                .withDescription("config.json file for defining log events");
		Option configOption = OptionBuilder
                .create("c");

        return options.addOption(portOption).addOption(databaseOption).addOption(helpOption).addOption(rawOption)
                .addOption(outputOption).addOption(configOption);
    }
	
    private static void exit(String message) {
        System.out.println("\r\n" + message + "\r\n");
      //  printHelp();
        System.exit(-1);
    }
    
	public static void main(String[] args) {
		  CommandLineParser parser = new PosixParser();
	        CommandLine commandLine = null;

	        try {
	            commandLine = parser.parse(addOptions(), args);
	        } catch (ParseException ex) {
	            exit("Invalid command arguments");
	        }
	        
	        
	}
}

@@ -1037,53 +1037,8 @@
 on;%0A
-import org.apache.commons.cli.OptionBuilder;%0A
 impo
@@ -1222,24 +1222,18 @@
 ons() %7B%0A
-        
+%09%09
 Options 
@@ -1253,32 +1253,26 @@
  Options();%0A
-        
+%09%09
 Option helpO
@@ -1314,33 +1314,16 @@
 (%22help%22)
-%0A                
 .desc(%22D
@@ -1341,32 +1341,26 @@
 %22).build();%0A
-        
+%09%09
 Option datab
@@ -1414,33 +1414,16 @@
 aseDir%22)
-%0A                
 .desc(%22D
@@ -1454,24 +1454,18 @@
 uild();%0A
-        
+%09%09
 Option p
@@ -1511,33 +1511,16 @@
 (%22port%22)
-%0A                
 .desc(%22S
@@ -1545,1028 +1545,102 @@
 ();%0A
-        %0A        OptionBuilder.withLongOpt(%22summary%22);%0A%09%09OptionBuilder%0A                .withDescription(%22Output as summary statics%22);%0A%09%09Option summaryOption = OptionBuilder%0A                .create(%22s%22);%0A        OptionBuilder.withLongOpt(%22output%22);%0A%09%09OptionBuilder%0A                .withDescription(%22Log output file%22);%0A%09%09Option outputOption = OptionBuilder%0A                .create(%22o%22);%0A        OptionBuilder.withLongOpt(%22raw%22);%0A%09%09OptionBuilder%0A                .withDescription(%22Output as raw delimited format%22);%0A%09%09Option rawOption = OptionBuilder%0A                .create(%22r%22);%0A%0A        %0A        OptionBuilder.hasOptionalArg();%0A%09%09OptionBuilder.withLongOpt(%22config%22);%0A%09%09OptionBuilder%0A                .withDescription(%22config.json file for defining log events%22);%0A%09%09Option configOption = OptionBuilder%0A                .create(%22c%22);%0A%0A        return options.addOption(portOption).addOption(databaseOption).addOption(helpOption).addOption(rawOption)%0A                .addOption(outputOption).addOption(configOption);%0A    %7D%0A%09%0A    
+%0A%09%09return options.addOption(portOption).addOption(databaseOption).addOption(helpOption);%0A%09%7D%0A%0A%09
 priv
@@ -1678,24 +1678,18 @@
 sage) %7B%0A
-        
+%09%09
 System.o
@@ -1731,17 +1731,12 @@
 %22);%0A
-      
+%09%09
 //
- 
  pri
@@ -1745,24 +1745,18 @@
 Help();%0A
-        
+%09%09
 System.e
@@ -1768,18 +1768,11 @@
 1);%0A
-    %7D%0A    
+%09%7D%0A
 %0A%09pu
@@ -1812,18 +1812,16 @@
 gs) %7B%0A%09%09
-  
 CommandL
@@ -1859,24 +1859,17 @@
 ser();%0A%09
-        
+%09
 CommandL
@@ -1898,35 +1898,18 @@
 ;%0A%0A%09
-        try %7B%0A%09            
+%09try %7B%0A%09%09%09
 comm
@@ -1953,24 +1953,17 @@
 args);%0A%09
-        
+%09
 %7D catch 
@@ -1989,20 +1989,10 @@
  %7B%0A%09
-            
+%09%09
 exit
@@ -2027,37 +2027,11 @@
 );%0A%09
-        %7D%0A%09        %0A%09        
+%09%7D%0A
 %0A%09%7D%0A

Remove deprecated CLI. fixes #12