package nebula;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.Reader;

import org.opennebula.client.Client;

public class Main {
	public static String usageString = "nebula command line : ";
	//nebula vm [stuff]
	public static void vm_do(String[] args,VirtualMachines vms){
		switch(args[1]){
			case "create":
			    //create a vm and print info
				break;
			case "list":
				vms.displayVM();
				break;
			case "delete":
			case "suspend":
			case "restart": 
			case "detail":
				if(args.length==2 ){
					//print usage
				}else{
					String id=args[2];
					int parsedId = 0;
					try{
						parsedId = Integer.parseInt(args[2]);
					}catch(NumberFormatException nfe){
						System.out.println("error: ID must be an integer");
					}
					switch(args[1]){
					case "delete":
						vms.deleteVM(parsedId);
						break;
					case "suspend":
						vms.suspendVM(parsedId);
						break;
					case "restart":
						vms.restartVM(parsedId);
						break;
					case "detail":
						//details
						break;
					}
				}
				break;
			case "migrate":
				if(args.length<4){
					//print usage
				}else{
					String vm_id_str=args[2];
					String destination_node_str=args[3];
					int vm_id=0;int destination_node=0;
					try{
						vm_id=Integer.parseInt(vm_id_str);
						destination_node=Integer.parseInt(destination_node_str);
					}catch(NumberFormatException nfe){
						System.out.println("error: ID must be an integer");
					}
					
				}
		}
	}
	
	//nebula node [stuff]
	public static void node_do(String[] args,Nodes ns){
		switch(args[1]){
		case "list":
			ns.listNodes();
			break;
		default:
			//print the usage
		}
	}
	public static void P(String arg){ System.out.println(arg); };
	public static String help_text= "nebula API tool"
			+ "usage :    ";
	public static void main(String[] args) {
		
		if(args.length==0){
			P(help_text);
		}
		else{
			switch(args[0]){
			case "help":
				P(help_text);
				break;
			case "vm":
				if(args.length==1){
					//print usage
				}else{
					vm_do(args, new VirtualMachines());
				}
				break;
			case "node":
				node_do(args,new Nodes());
				break;
			case "version":
				(new Nebula()).getVersion();
				break;
			}
		}
	}

}

@@ -214,90 +214,9 @@
  %7B%0A%09
-public static String usageString = %22nebula command line : %22;%0A%09//nebula vm %5Bstuff%5D
 %0A
+
 %09pub
@@ -296,73 +296,8 @@
 %5D)%7B%0A
-%09%09%09case %22create%22:%0A%09%09%09    //create a vm and print info%0A%09%09%09%09break;%0A
 %09%09%09c
@@ -441,37 +441,37 @@
 ==2 )%7B%0A%09%09%09%09%09
-//print usage
+P(help_text);
 %0A%09%09%09%09%7Delse%7B%0A
@@ -900,38 +900,36 @@
 %09%09%09%09
-case %22detail%22:%0A%09%09%09%09%09%09//details
+default:%0A%09%09%09%09%09%09P(help_text);
 %0A%09%09%09
@@ -1375,24 +1375,54 @@
 %09%09%09%09%09%0A%09%09%09%09%7D%0A
+%09%09%09default:%0A%09%09%09%09P(help_text);%0A
 %09%09%7D%0A%09%7D%0A%09%0A%09//
@@ -1575,25 +1575,21 @@
 %0A%09%09%09
-//print the usage
+P(help_text);
 %0A%09%09%7D
@@ -1708,30 +1708,16 @@
 tool
-%22%0A%09%09%09+ %22usage :    
+s%5Cn
 %22;%0A
+%09%0A
 %09pub
@@ -1754,19 +1754,17 @@
 args) %7B%0A
-%09%09
 %0A
+
 %09%09if(arg
@@ -1910,37 +1910,37 @@
 h==1)%7B%0A%09%09%09%09%09
-//print usage
+P(help_text);
 %0A%09%09%09%09%7Delse%7B%0A

put in help messages