package com.github.wiliamsouza.apollo;

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

public class Agent {

	public static void main(String[] args) {
		String config = "/etc/apollo/agent.conf";
		CommandLine cmd;

		Option configFile  = OptionBuilder.withArgName("file")
						  .hasArg()
						  .withDescription("Apollo agent configuration file.")
						  .create("config");
		Options options = new Options();
		options.addOption(configFile);
		options.addOption("h", "help", false, "Print this message.");

		CommandLineParser parser = new BasicParser();
		try {
			cmd = parser.parse(options, args);
			if (cmd.hasOption("help")) {
				HelpFormatter formatter = new HelpFormatter();
				formatter.printHelp("apollo", options);
			}
			String conf = cmd.getOptionValue("config");
			if (conf != null) {
				config = conf;
			}
		}
		catch (ParseException e){
			System.err.println("Option error: " + e.getMessage());
		}

		DeviceMonitor monitor = new DeviceMonitor();
		monitor.start();
        try {
            monitor.run();
        } catch (Exception e) {
            e.printStackTrace();
        }
        //monitor.finish();

		System.out.println(config);
		System.out.println("Apollo agent. \n");
	}
}

@@ -404,17 +404,20 @@
 gent %7B%0A%0A
-%09
+    
 public s
@@ -449,18 +449,24 @@
 args) %7B%0A
-%09%09
+        
 String c
@@ -499,18 +499,24 @@
 .conf%22;%0A
-%09%09
+        
 CommandL
@@ -525,18 +525,24 @@
 e cmd;%0A%0A
-%09%09
+        
 Option c
@@ -592,32 +592,68 @@
 e%22)%0A
-%09%09%09%09%09%09  .hasArg()%0A%09%09%09%09%09%09
+                          .hasArg()%0A                        
   .w
@@ -707,14 +707,32 @@
 .%22)%0A
-%09%09%09%09%09%09
+                        
   .c
@@ -748,18 +748,24 @@
 nfig%22);%0A
-%09%09
+        
 Options 
@@ -789,18 +789,24 @@
 ions();%0A
-%09%09
+        
 options.
@@ -828,18 +828,24 @@
 gFile);%0A
-%09%09
+        
 options.
@@ -899,18 +899,24 @@
 ge.%22);%0A%0A
-%09%09
+        
 CommandL
@@ -957,19 +957,34 @@
 ();%0A
-%09%09try %7B%0A%09%09%09
+        try %7B%0A            
 cmd 
@@ -1014,19 +1014,28 @@
  args);%0A
-%09%09%09
+            
 if (cmd.
@@ -1055,20 +1055,32 @@
 lp%22)) %7B%0A
-%09%09%09%09
+                
 HelpForm
@@ -1118,20 +1118,32 @@
 tter();%0A
-%09%09%09%09
+                
 formatte
@@ -1178,16 +1178,34 @@
 s);%0A
-%09%09%09%7D%0A%09%09%09
+            %7D%0A            
 Stri
@@ -1244,19 +1244,28 @@
 nfig%22);%0A
-%09%09%09
+            
 if (conf
@@ -1280,38 +1280,71 @@
 ) %7B%0A
-%09%09%09%09config = conf;%0A%09%09%09%7D%0A%09%09%7D%0A%09%09
+                config = conf;%0A            %7D%0A        %7D%0A        
 catc
@@ -1369,11 +1369,20 @@
 e)%7B%0A
-%09%09%09
+            
 Syst
@@ -1436,15 +1436,27 @@
 ));%0A
-%09%09%7D%0A%0A%09%09
+        %7D%0A%0A        
 Devi
@@ -1496,18 +1496,24 @@
 itor();%0A
-%09%09
+        
 monitor.
@@ -1666,18 +1666,24 @@
 ish();%0A%0A
-%09%09
+        
 System.o
@@ -1706,10 +1706,16 @@
 g);%0A
-%09%09
+        
 Syst
@@ -1754,9 +1754,12 @@
 %22);%0A
-%09
+    
 %7D%0A%7D%0A

Converted indents to 4 spaces