package com.github.aureliano.achmed.server.helper;

import java.util.Properties;

import com.github.aureliano.achmed.common.exception.AchmedException;
import com.github.aureliano.achmed.common.helper.FileHelper;
import com.github.aureliano.achmed.common.helper.PropertyHelper;
import com.github.aureliano.achmed.common.helper.StringHelper;

public final class ApplicationHelper {

	private ApplicationHelper() {}
	
	public static void execute(String path) {
		throw new AchmedException("Not implemented yet.");
	}
	
	public static String help() {
		String help = FileHelper.readResource("meta/help");
		return help;
	}
	
	public static String version() {
		Properties properties = PropertyHelper.loadProperties("meta/version.properties");
		
		return new StringBuilder()
			.append(properties.get("version"))
			.append(":")
			.append(properties.get("release"))
			.append(" (")
			.append(properties.get("date"))
			.append(")\n")
			.toString();
	}
	
	public static String error(String[] args) {
		if (args.length == 0) {
			return "Port number parameter is mandatory.";
		} else if ((args.length == 2) && ("-p".equals(args[0])) && (!args[1].matches("\\d+"))) {
			return "Port number must be a valid integer.";
		} else {
			return "Don't know how to handle such command: " + StringHelper.join(args, " ");
		}
	}
}
@@ -79,77 +79,8 @@
 s;%0A%0A
-import com.github.aureliano.achmed.common.exception.AchmedException;%0A
 impo
@@ -128,32 +128,32 @@
 per.FileHelper;%0A
+
 import com.githu
@@ -263,16 +263,79 @@
 gHelper;
+%0Aimport com.github.aureliano.achmed.server.AchmedServerHandler;
 %0A%0Apublic
@@ -442,65 +442,306 @@
 ng p
-ath
+ort
 ) %7B%0A%09%09
-throw new AchmedException(%22Not implemented yet.%22
+Integer portNumber = Integer.parseInt(port);%0A%09%09AchmedServerHandler.instance().startUp(portNumber);%0A%09%7D%0A%09%0A%09public static void addShutDownHook() %7B%0A%09%09Runtime.getRuntime().addShutdownHook(new Thread() %7B%0A%09%09%09@Override%0A%09%09%09public void run() %7B%0A%09%09%09%09AchmedServerHandler.instance().shutDown();%0A%09%09%09%7D%0A%09%09%7D
 );%0A%09

Add methods to execute server and to append shut down hook.