[Pkg-mono-svn-commits] rev 376 - mono-vhostmanager/src

Pablo Fischer pabl0-guest@quantz.debian.org
Sat, 28 Feb 2004 07:20:21 +0100


Author: pabl0-guest
Date: 2004-02-28 07:20:21 +0100 (Sat, 28 Feb 2004)
New Revision: 376

Modified:
   mono-vhostmanager/src/Manager.cs
   mono-vhostmanager/src/VirtualSchema.cs
Log:
* VirtualSchema.cs:
 + Fixed the hostArray.Count, by my fault, I uploaded a corrupt .cs file 
   where I was trying to access a HostArray from a int32
* Manager.cs:
 + Fixed the command line args messages
 + Added the HowToUseIt method to print the 'help'
 + We check the total of args that each option requires, and validate each one, 
   so nobody will have errors without args or corrupt args.



Modified: mono-vhostmanager/src/Manager.cs
===================================================================
--- mono-vhostmanager/src/Manager.cs	2004-02-28 06:16:51 UTC (rev 375)
+++ mono-vhostmanager/src/Manager.cs	2004-02-28 06:20:21 UTC (rev 376)
@@ -96,6 +96,11 @@
     
     //We don't need this if we are just going to print or repair
     if(action == "print") {
+      //But.. what is the option?
+      if(option.Split('=')[0] != "--config-file") {
+	Console.WriteLine("[ONR] {0} Option not Recognized", option.Split('=')[0]);
+	System.Environment.Exit(0);
+      }      
       //Get the file name, after the '=' char
       //Does the option has a value?
       try {
@@ -153,16 +158,16 @@
 	  System.Environment.Exit(0);
 	}
 	break;
-    case "--alias":
-      try {
-	host_alias = option.Split('=')[1];
-      }catch(System.IndexOutOfRangeException ex) {
-	Console.WriteLine("No values for {0}", option.Split('=')[0]);
-	System.Environment.Exit(0);
-      }
-      //Remove the /      
-      host_alias.Replace("/", "");  
-      break;
+      case "--alias":
+	try {
+	  host_alias = option.Split('=')[1];
+	}catch(System.IndexOutOfRangeException ex) {
+	  Console.WriteLine("No values for {0}", option.Split('=')[0]);
+	  System.Environment.Exit(0);
+	}
+	//Remove the /      
+	host_alias.Replace("/", "");  
+	break;
     default:
       Console.WriteLine("[ONR] {0} Option not Recognized", option.Split('=')[0]);
       System.Environment.Exit(0);
@@ -172,7 +177,26 @@
   }
 
 
+  ///<summary>
+  ///A brief explanation of how to use nethostmanager
+  ///</summary>
+  public static void HowToUse() {
+    Console.WriteLine("VirtualHost Manager"); 
+    Console.WriteLine("Use: netvirtualhost [action] [options]\n");
+    Console.WriteLine("Actions:");
+    Console.WriteLine(" add                         Add a VirtualHost");
+    Console.WriteLine(" del                         Delete a VirtualHost");
+    Console.WriteLine(" print                       Prints the file to screen in the xsp format (/alias:path)");
+    Console.WriteLine("Options:");
+    Console.WriteLine("   --config-file=<file>      The full path where the config file is");
+    Console.WriteLine("   --alias=<alias>           The alias that you want for the host");
+    Console.WriteLine("   --path=<path>             The path where your web files are");
+    Console.WriteLine("\nFor example:");
+    Console.WriteLine(" netvirtualhost add --config-file=/etc/xsp/files.conf --alias=/examples --path=/usr/share/foo/bar\n");
+    System.Environment.Exit(0);  
+  }
 
+
   ///<summary>
   ///The main
   ///</summary>
@@ -180,24 +204,20 @@
     try {
       action = args[0];
     }catch(System.IndexOutOfRangeException ex) {
+      HowToUse();
     }
   
-    if(args.Length == 0 || args.Length < 4 && action != "print") {
-      Console.WriteLine("VirtualHost Manager");
-      Console.WriteLine("Use: mono-vhostmanager [action] [options]\n");
-      Console.WriteLine("Actions:");
-      Console.WriteLine(" add                         Add a VirtualHost");
-      Console.WriteLine(" del                         Delete a VirtualHost");
-      Console.WriteLine(" print                       Prints the file to screen in the xsp format (/alias:path)");
-      Console.WriteLine("Options:");
-      Console.WriteLine("   --config-file=<file>      The full path where the config file is");
-      Console.WriteLine("   --alias=<alias>           The alias that you want for the host");
-      Console.WriteLine("   --path=<path>             The path where your web files are");
-      Console.WriteLine("\nFor example:");
-      Console.WriteLine(" mono-vhostmanager add --config-file=/etc/xsp/files.conf --alias=/examples --path=/usr/share/foo/bar\n");
-      System.Environment.Exit(0);
+    //Evaluation cases to show the help menu or start the app
+    //Print action and not the 2 args.. out!
+    if(action == "print" && args.Length != 2) {
+      HowToUse();
+    }
+    
+    //Add and remove
+    if((action == "add" || action == "del") && args.Length != 4) {
+      HowToUse();
+    }
 
-    }
     //Ok, read the command line args
     else {
       action = args[0];

Modified: mono-vhostmanager/src/VirtualSchema.cs
===================================================================
--- mono-vhostmanager/src/VirtualSchema.cs	2004-02-28 06:16:51 UTC (rev 375)
+++ mono-vhostmanager/src/VirtualSchema.cs	2004-02-28 06:20:21 UTC (rev 376)
@@ -37,8 +37,8 @@
   }
 
   public void PrintHosts() {
-    if(position.hostArray.Count == 0) {
-      Console.Write("[NHF] Sorry, No Hosts Found");
+    if(hostArray.Count == 0) {
+      Console.Write("[NHF] Sorry, No Hosts Found\n");
     }
     else {
       for(position=0; position<hostArray.Count; position++)