protected ParsedCommandLine(CacheEnumerable<string> args) { var assemblypath = Assembly.GetEntryAssembly().Location; _switches = new XDictionary<string, List<string>>(); var v = Environment.GetEnvironmentVariable("_" + Path.GetFileNameWithoutExtension(assemblypath) + "_"); if (!string.IsNullOrEmpty(v)) { var extraSwitches = SplitArgs(v).Where(each => each.StartsWith("--")); if (!args.IsNullOrEmpty()) { args = args.Concat(extraSwitches); } } // load a <exe>.properties file in the same location as the executing assembly. var propertiespath = "{0}\\{1}.properties".format(Path.GetDirectoryName(assemblypath), Path.GetFileNameWithoutExtension(assemblypath)); if (File.Exists(propertiespath)) { LoadConfiguration(propertiespath); } var argEnumerator = args.GetEnumerator(); //while(firstarg < args.Length && args[firstarg].StartsWith("--")) { while (argEnumerator.MoveNext() && argEnumerator.Current.StartsWith("--")) { var arg = argEnumerator.Current.Substring(2).ToLower(); var param = ""; int pos; if ((pos = arg.IndexOf("=")) > -1) { param = argEnumerator.Current.Substring(pos + 3); arg = arg.Substring(0, pos); /* if(string.IsNullOrEmpty(param) || string.IsNullOrEmpty(arg)) { "Invalid Option :{0}".Print(argEnumerator.Current.Substring(2).ToLower()); switches.Clear(); switches.Add("help", new List<string>()); return switches; } */ } if (arg.Equals("load-config")) { // loads the config file, and then continues parsing this line. LoadConfiguration(param); // firstarg++; continue; } #if TODO // make an extensibility model for intercepting arguments // so that console project can do this. if (arg.Equals("list-bugtracker") || arg.Equals("list-bugtrackers")) { // the user is asking for the bugtracker URLs for this application. ListBugTrackers(); continue; } if (arg.Equals("open-bugtracker") || arg.Equals("open-bugtrackers")) { // the user is asking for the bugtracker URLs for this application. OpenBugTracker(); continue; } #endif if (!_switches.ContainsKey(arg)) { _switches.Add(arg, new List<string>()); } _switches[arg].Add(param); // firstarg++; } _parameters = args.Where(argument => !(argument.StartsWith("--"))); }
protected ParsedCommandLine(CacheEnumerable <string> args) { var assemblypath = Assembly.GetEntryAssembly().Location; _switches = new XDictionary <string, List <string> >(); var v = Environment.GetEnvironmentVariable("_" + Path.GetFileNameWithoutExtension(assemblypath) + "_"); if (!string.IsNullOrEmpty(v)) { var extraSwitches = SplitArgs(v).Where(each => each.StartsWith("--")); if (!args.IsNullOrEmpty()) { args = args.Concat(extraSwitches); } } // load a <exe>.properties file in the same location as the executing assembly. var propertiespath = "{0}\\{1}.properties".format(Path.GetDirectoryName(assemblypath), Path.GetFileNameWithoutExtension(assemblypath)); if (File.Exists(propertiespath)) { LoadConfiguration(propertiespath); } var argEnumerator = args.GetEnumerator(); //while(firstarg < args.Length && args[firstarg].StartsWith("--")) { while (argEnumerator.MoveNext() && argEnumerator.Current.StartsWith("--")) { var arg = argEnumerator.Current.Substring(2).ToLower(); var param = ""; int pos; if ((pos = arg.IndexOf("=")) > -1) { param = argEnumerator.Current.Substring(pos + 3); arg = arg.Substring(0, pos); /* * if(string.IsNullOrEmpty(param) || string.IsNullOrEmpty(arg)) { * "Invalid Option :{0}".Print(argEnumerator.Current.Substring(2).ToLower()); * switches.Clear(); * switches.Add("help", new List<string>()); * return switches; * } */ } if (arg.Equals("load-config")) { // loads the config file, and then continues parsing this line. LoadConfiguration(param); // firstarg++; continue; } #if TODO // make an extensibility model for intercepting arguments // so that console project can do this. if (arg.Equals("list-bugtracker") || arg.Equals("list-bugtrackers")) { // the user is asking for the bugtracker URLs for this application. ListBugTrackers(); continue; } if (arg.Equals("open-bugtracker") || arg.Equals("open-bugtrackers")) { // the user is asking for the bugtracker URLs for this application. OpenBugTracker(); continue; } #endif if (!_switches.ContainsKey(arg)) { _switches.Add(arg, new List <string>()); } _switches[arg].Add(param); // firstarg++; } _parameters = args.Where(argument => !(argument.StartsWith("--"))); }