5c3460a1427ea0a8ed4181ddfb9b88cf8ce976bc
diff --git a/src/main.cs b/src/main.cs
index d8cfba0..a10b2c9 100644
--- a/src/main.cs
+++ b/src/main.cs
@@ -13,59 +13,89 @@ using FSpot.Utils;
 using FSpot.UI.Dialog;
 using FSpot.Extensions;
 using Hyena;
+using Hyena.CommandLine;
 
 namespace FSpot 
 {
-	public static class Driver {
-		static void Version ()
+	public static class Driver
+	{
+		private static void ShowVersion ()
 		{
+			//TODO: Change copyright!?
 			Console.WriteLine (
 				"F-Spot  {0}" + Environment.NewLine +
+				"http://f-spot.org" + Environment.NewLine +
+				//"Copyright 2005-{0} Novell, Inc. and Contributors.", DateTime.Now.Year);
 				"\t(c)2003-2009, Novell Inc" + Environment.NewLine +
 				"\t(c)2009 Stephane Delcroix" + Environment.NewLine +
 				"Personal photo management for the GNOME Desktop" + Environment.NewLine,
 				FSpot.Defines.VERSION);
 		}
 
-		static void Versions ()
+		private static void ShowAssemblyVersions ()
 		{
-		    Version ();
-	            Console.WriteLine (".NET Version: " + Environment.Version.ToString());
-	            Console.WriteLine (String.Format("{0}Assembly Version Information:", Environment.NewLine));
-
-	            foreach(Assembly asm in AppDomain.CurrentDomain.GetAssemblies()) {
-			    AssemblyName name = asm.GetName();
-	                    Console.WriteLine ("\t" + name.Name + " (" + name.Version.ToString () + ")");
+			ShowVersion ();
+			Console.WriteLine ("Mono/.NET Version: " + Environment.Version.ToString ());
+			Console.WriteLine (String.Format ("{0}Assembly Version Information:", Environment.NewLine));
+			
+			foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies ()) 
+			{
+				AssemblyName name = asm.GetName ();
+				Console.WriteLine ("\t" + name.Name + " (" + name.Version.ToString () + ")");
 			}
 		}
-
-		static void Help ()
+		
+		private static void ShowHelp ()
 		{
-			Version ();
-			Console.WriteLine ();
-			Console.WriteLine (
-				"Usage: f-spot [options] " + Environment.NewLine +
-				"Options:" + Environment.NewLine +
-				"-b -basedir PARAM   path to the photo database folder" + Environment.NewLine +
-				"-? -help -usage     Show this help list" + Environment.NewLine +
-				"-i -import PARAM    import from the given uri" + Environment.NewLine +
-				"-p -photodir PARAM  default import folder" + Environment.NewLine +
-				"-shutdown           shutdown a running f-spot instance" + Environment.NewLine +
-				"-slideshow          display a slideshow" + Environment.NewLine +
-				"-V -version         Display version and licensing information" + Environment.NewLine +
-				"-versions           Display version and dependencies informations" + Environment.NewLine +
-				"-v -view            view file(s) or directory(ies)");
+			Hyena.CommandLine.Layout commands = new Hyena.CommandLine.Layout (
+				new LayoutGroup ("help", "Help Options",
+					new LayoutOption ("help", "Show this help"),
+					new LayoutOption ("help-options", "Show command line options"),
+					new LayoutOption ("help-all", "Show all options"),
+					new LayoutOption ("version", "Show version information"),
+					new LayoutOption ("versions", "Show detailed version information")),
+				new LayoutGroup ("options", "General options",
+					new LayoutOption ("basedir=DIR", "Path to the photo database folder"),
+					new LayoutOption ("import=FILE", "Path to the photo database folder"),
+					new LayoutOption ("photodir=DIR", "Path to the photo database folder"),
+					new LayoutOption ("view=FILE1;FILE2;DIR...", "View file(s) or directories"),
+					new LayoutOption ("shutdown", "Shut down a running instance of F-Spot"),
+					new LayoutOption ("slideshow", "Display a slideshow"),
+					new LayoutOption ("debug", "Run in debug mode")));
+			
+			if (ApplicationContext.CommandLine.Contains ("help-all")) {
+				Console.WriteLine (commands);
+				return;
+			}
+			
+			List<string> errors = null;
+			foreach (KeyValuePair<string, string> argument in ApplicationContext.CommandLine.Arguments) {
+				switch (argument.Key) {
+					case "help": Console.WriteLine (commands.ToString ("help")); break;
+					case "help-options": Console.WriteLine (commands.ToString ("options")); break;
+					default:
+						if (argument.Key.StartsWith ("help")) {
+							(errors ?? (errors = new List<string> ())).Add (argument.Key);
+						}
+						break;
+				}
+			}
+			
+			if (errors != null) {
+				Console.WriteLine (commands.LayoutLine (String.Format (
+					"The following help arguments are invalid: {0}",
+					Hyena.Collections.CollectionExtensions.Join (errors, "--", null, ", "))));
+			}
 		}
 
 		static int Main (string [] args)
 		{
-			List<string> uris = new List<string> ();
 			Unix.SetProcessName (Defines.PACKAGE);
-            ThreadAssist.InitializeMainThread ();
-            XdgThumbnailSpec.DefaultLoader = (uri) => {
-                using (var file = ImageFile.Create (uri))
-                    return file.Load ();
-            };
+			ThreadAssist.InitializeMainThread ();
+			XdgThumbnailSpec.DefaultLoader = (uri) => {
+				using (var file = ImageFile.Create (uri))
+					return file.Load ();
+			};
 
 			// Options and Option parsing
 			bool shutdown = false;
@@ -77,103 +107,103 @@ namespace FSpot
 			Catalog.Init ("f-spot", Defines.LOCALE_DIR);
 			
 			FSpot.Global.PhotoDirectory = Preferences.Get<string> (Preferences.STORAGE_PATH);
-			for (int i = 0; i < args.Length && !shutdown; i++) {
-				switch (args [i]) {
-				case "-h": case "-?": case "-help": case "--help": case "-usage":
-					Help ();
-					return 0;
-
-				case "-shutdown": case "--shutdown":
-					Log.Information ("Shutting down existing F-Spot server...");
-					shutdown = true;
-					break;
-
-				case "-b": case "-basedir": case "--basedir":
-					if (i+1 == args.Length || args[i+1].StartsWith ("-")) {
-						Log.Error ("f-spot: -basedir option takes one argument");
-						return 1;
-					}
-					FSpot.Global.BaseDirectory = args [++i];
-					Log.InformationFormat ("BaseDirectory is now {0}", FSpot.Global.BaseDirectory);
-					break;
-
-				case "-p": case "-photodir": case "--photodir":
-					if (i+1 == args.Length || args[i+1].StartsWith ("-")) {
-						Log.Error ("f-spot: -photodir option takes one argument");
-						return 1;
-					}
-					FSpot.Global.PhotoDirectory = System.IO.Path.GetFullPath (args [++i]);
-					Log.InformationFormat ("PhotoDirectory is now {0}", FSpot.Global.PhotoDirectory);
-					break;
-
-				case "-i": case "-import": case "--import":
-					if (i+1 == args.Length) {
-						Log.Error ("f-spot: -import option takes one argument");
-						return 1;
-					}
-					import_uri = args [++i];
-					break;
-
-				case "-slideshow": case "--slideshow":
-					slideshow = true;
-					break;
-
-				case "-v": case "-view": case "--view":
-					if (i+1 == args.Length || args[i+1].StartsWith ("-")) {
-						Log.Error ("f-spot: -view option takes (at least) one argument");
-						return 1;
-					}
-					view = true;
-					while (!(i+1 == args.Length) && !args[i+1].StartsWith ("-"))
-						uris.Add (args [++i]);
-	//				if (!System.IO.Directory.Exists (args[i+1]) && !System.IO.File.Exists (args[i+1])) {
-	//					Log.Error ("f-spot: -view argument must be an existing file or directory");
-	//					return 1;
-	//				}
-					break;
-
-				case "-versions": case "--versions":
-					Versions ();
-					return 0;
-
-				case "-V": case "-version": case "--version":
-					Version ();
-					return 0;
-
-				case "--debug":
-					Log.Debugging = true;
-					// Debug GdkPixbuf critical warnings
-					GLib.LogFunc logFunc = new GLib.LogFunc (GLib.Log.PrintTraceLogFunction);
-					GLib.Log.SetLogHandler ("GdkPixbuf", GLib.LogLevelFlags.Critical, logFunc);
+			
+			if (ApplicationContext.CommandLine.ContainsStart ("help")) {
+				ShowHelp ();
+			}
+			
+			if (ApplicationContext.CommandLine.Contains ("version")) {
+				ShowVersion ();
+			}
+			
+			if (ApplicationContext.CommandLine.Contains ("versions")) {
+				ShowAssemblyVersions ();
+			}
+			
+			if (ApplicationContext.CommandLine.Contains ("shutdown")) {
+				Log.Information ("Shutting down existing F-Spot server...");
+				shutdown = true;
+			}
+			
+			if (ApplicationContext.CommandLine.Contains ("slideshow")) {
+				Log.Information ("Running F-Spot in slideshow mode.");
+				slideshow = true;
+			}
+			
+			if (ApplicationContext.CommandLine.Contains ("basedir")) {
+				string dir = ApplicationContext.CommandLine ["basedir"];
+				
+				if (!string.IsNullOrEmpty (dir))
+				{
+					FSpot.Global.BaseDirectory = dir;
+					Log.InformationFormat ("BaseDirectory is now {0}", dir);
+				} else {
+					Log.Error ("f-spot: -basedir option takes one argument");
+					return 1;
+				}
+			}
+			
+			if (ApplicationContext.CommandLine.Contains ("photodir")) {
+				string dir = ApplicationContext.CommandLine ["photodir"];
+				
+				if (!string.IsNullOrEmpty (dir))
+				{
+					FSpot.Global.PhotoDirectory = dir;
+					Log.InformationFormat ("PhotoDirectory is now {0}", dir);
+				} else {
+					Log.Error ("f-spot: -photodir option takes one argument");
+					return 1;
+				}
+			}
+			
+			if (ApplicationContext.CommandLine.Contains ("import")) {
+				string dir = ApplicationContext.CommandLine ["import"];
+				
+				if (!string.IsNullOrEmpty (dir))
+				{
+					import_uri = dir;
+				} else {
+					Log.Error ("f-spot: -import option takes one argument");
+					return 1;
+				}
+			}
+			
+			List <string> uris = new List <string> ();
+			if (ApplicationContext.CommandLine.Contains ("view")) {
+				string dir = ApplicationContext.CommandLine ["view"];
+				
+				if (!string.IsNullOrEmpty (dir))
+				{
+					uris = new List<string> (dir.Split (';'));
+				} else {
+					Log.Error ("f-spot: -view option takes one argument");
+					return 1;
+				}
+			}
 
-					// Debug Gtk critical warnings
-					GLib.Log.SetLogHandler ("Gtk", GLib.LogLevelFlags.Critical, logFunc);
+			if (ApplicationContext.CommandLine.Contains ("debug")) {
+				Log.Debugging = true;
+				// Debug GdkPixbuf critical warnings
+				GLib.LogFunc logFunc = new GLib.LogFunc (GLib.Log.PrintTraceLogFunction);
+				GLib.Log.SetLogHandler ("GdkPixbuf", GLib.LogLevelFlags.Critical, logFunc);
 
-					// Debug GLib critical warnings
-					GLib.Log.SetLogHandler ("GLib", GLib.LogLevelFlags.Critical, logFunc);
+				// Debug Gtk critical warnings
+				GLib.Log.SetLogHandler ("Gtk", GLib.LogLevelFlags.Critical, logFunc);
 
-					//Debug GLib-GObject critical warnings
-					GLib.Log.SetLogHandler ("GLib-GObject", GLib.LogLevelFlags.Critical, logFunc);
+				// Debug GLib critical warnings
+				GLib.Log.SetLogHandler ("GLib", GLib.LogLevelFlags.Critical, logFunc);
 
-					GLib.Log.SetLogHandler ("GLib-GIO", GLib.LogLevelFlags.Critical, logFunc);
+				//Debug GLib-GObject critical warnings
+				GLib.Log.SetLogHandler ("GLib-GObject", GLib.LogLevelFlags.Critical, logFunc);
 
-					break;
-				case "--uninstalled": case "--gdb": case "--valgrind": case "--sync":
-					break;
-				default:
-					if (args [i].StartsWith ("--profile"))
-						break;
-					if (args [i].StartsWith ("--trace"))
-						break;
-					Log.DebugFormat ("Unparsed argument >>{0}<<", args [i]);
-					break;
-				}
+				GLib.Log.SetLogHandler ("GLib-GIO", GLib.LogLevelFlags.Critical, logFunc);
 			}
 
 			// Validate command line options
 			if ( (import_uri != null && (view || shutdown || slideshow)) ||
-			     (view && (shutdown || slideshow)) ||
-			     (shutdown && slideshow) ) {
+				(view && (shutdown || slideshow)) ||
+				(shutdown && slideshow) )
+			{
 				Log.Error ("Can't mix -import, -view, -shutdown or -slideshow");
 				return 1;
 			}
@@ -231,7 +261,7 @@ namespace FSpot
 					foreach (string s in uris)
 						list.AddUnknown (s);
 					if (list.Count == 0) {
-						Help ();
+						ShowHelp ();
 						return 1;
 					}
 					App.Instance.View (list);
