--- a/trunk/cforge/cforge/Program.cs +++ b/trunk/cforge/cforge/Program.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Reflection; using System.Text; using System.Threading.Tasks; @@ -10,7 +11,12 @@ { static void Main(string[] args) { - Console.WriteLine("cforge\r\n"); + Console.WriteLine(""); + Console.WriteLine(@"----------------------------------------------------------------------------"); + Console.WriteLine("cforge started"); + Console.WriteLine(@"----------------------------------------------------------------------------"); + Console.WriteLine(""); + if (args.Length == 1 && args[0].StartsWith("cforge:")) { @@ -27,37 +33,55 @@ string s = System.Uri.UnescapeDataString(arg.Remove(0, command.Length + 1)); s = System.Uri.UnescapeDataString(s); newargs.Add(s); - + args = newargs.ToArray(); } + - if(!Helper.CheckRegistryProtocol()) + if (!Helper.CheckRegistryProtocol()) { Console.WriteLine(@"[WARNING] URL Handler is not registered. CFORGE: links will not work properly. Use RegisterURLHandler.bat to do this (at <CODESYS Installation folder>\CFORGE\ )"); } List<String> liScripts = Helper.GetAllScripts(); + + bool bDebug = false; for (int i = 0; i < args.Length; i++) { switch (args[i]) { - case "--register-url-handler": - Helper.RegisterProtocol(); - break; - case "--add-to-path": - Helper.AddToSystemPath(); + case "-d": + bDebug = true; + if (Helper.IsUserElevated()) + Console.WriteLine("Running elevated"); break; - case "--list-scripts": + // fallthrough intended + case "-v": + case "--version": + + Version version = Assembly.GetEntryAssembly().GetName().Version; + Console.WriteLine("Version: " + version.ToString()); + break; - Console.WriteLine("List all scripts: "); - foreach (String item in liScripts) + case "--setup": + if (!Helper.IsUserElevated()) + Helper.RunElevated("--setup"); + else { - Console.WriteLine(" -" + item); + Helper.RegisterProtocol(bDebug); + Helper.AddToSystemPath(bDebug); } break; - + + + case "--license-info": + Helper.ShowLicenseInfo(); + break; + + + /* fallthrough intended ! */ case "--help": case "-h": @@ -66,30 +90,64 @@ default: // check if we have matching script: - if(liScripts.Contains(args[i])) + if (args[i].StartsWith("--")) { - // the rest of the command is passed as argument to the script - string[] newargs = new List<string>(args).GetRange(i, args.Length - i - 1).ToArray(); - Helper.ExecuteIPyScript(args[i], newargs); + String command = args[i].Replace("--", ""); + if (liScripts.Contains(command)) + { + // the rest of the command is passed as argument to the script + + string[] newargs = args.Skip(i + 1).ToArray(); + + Helper.ExecuteIPyScript(command, newargs, bDebug); + // as we "used" all params... + i = args.Length; + } + else + { + ShowUsage(); + } } break; } } + + if (args.Length == 0) + ShowUsage(); + + Console.WriteLine(""); + Console.WriteLine(@"----------------------------------------------------------------------------"); + Console.WriteLine("cforge finished."); + Console.WriteLine(@"----------------------------------------------------------------------------"); + Console.WriteLine(""); + + //Console.ReadLine(); } static void ShowUsage() { - Console.WriteLine(@"usage: cforge <command> [options]"); + // pad right 32 for description ;-) + Console.WriteLine(@"usage: cforge <command> <arguments>"); Console.WriteLine(@""); - Console.WriteLine(@"commands:"); - Console.WriteLine(@"-h/--help: show this help"); - Console.WriteLine(@"--register-url-handler register cforge url handler in windows registry"); - Console.WriteLine(@"--add-to-path add this cforge folder to windows path variable"); + Console.WriteLine(@"internal commands:"); + Console.WriteLine(@"-h/--help show this help"); + Console.WriteLine(@"--setup register cforge url handler and add cforge to path"); + Console.WriteLine(@"--license-info show license information"); + Console.WriteLine(@"-v/--version show version information"); + Console.WriteLine(@""); - Console.WriteLine(@"--list-scripts list all available scripts (ironpython subcommands)"); + Console.WriteLine(@""); + Console.WriteLine(@"external commands (scripts):"); + Console.WriteLine(@"------------------------------"); // generic part - + + List<String> liCommands = Helper.GetAllScripts(); + foreach (String command in liCommands) + { + Helper.ShowUsageIPyScript(command, false); + } + Console.WriteLine(@""); Console.WriteLine(@""); }