/// <summary> Callback to parse the command line options. </summary> public override void Load() { var args = CmdLineHelper.FilterArguments(Args); var switches = CmdLineHelper.FilterSwitches(Args); // with the above we split up all the switches and arguments into separate variables // switches - contains anything starting with a / - -- // args - contains everything else Data = SplitLoadFunc(args, switches); }
/// <summary> Determine if someone has specified an alternative configuration file. </summary> /// <param name="opts"> Command line options. </param> /// <returns> The configuration file path. </returns> private static string GetCfgFilePath(IEnumerable <string> opts) { // Default path for configuration file var cfgfile = "Settings1.json"; // search the switches for a cfgfile setting i.e. --cfgfile="Settings2.json" var switches = CmdLineHelper.FilterSwitches(opts); if (switches.ContainsKey("cfgfile")) { cfgfile = switches["cfgfile"]; // If the user has specified one then warn if it doesn't exist if (!File.Exists(cfgfile)) { Console.WriteLine($"Warning unable to locate configuration file: {cfgfile}"); } } return(cfgfile); }
/// <summary> Callback to parse the command line options. </summary> public override void Load() { var splitindex = Array.IndexOf(Args, "--"); var arr1 = Args.Take(splitindex).ToList(); var arr2 = Args.Skip(splitindex).ToList(); var args1 = CmdLineHelper.FilterArguments(arr1); var switches1 = CmdLineHelper.FilterSwitches(arr1); var args2 = CmdLineHelper.FilterArguments(arr2); var switches2 = CmdLineHelper.FilterSwitches(arr2); // This is the same as the split provider // However we split the arguments and switches into two groups // seperated by wherever -- shows up on the command line // This is often used by apps that launch / act as a proxy for other apps and need to pass options across to them Data = DoubleSplitLoadFunc(args1, switches1, args2, switches2); }
/// <summary> Loads the given options into key value pairs. </summary> /// <param name="opts"> The Options to load. </param> /// <returns> The options in key / value pairs </returns> public static Dictionary <string, string> Load(string[] opts) { var data = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); // Get the arguments / switches var args_noswitches = CmdLineHelper.FilterArguments(opts); var switches = CmdLineHelper.FilterSwitches(opts); // Make a note of the configuration file path if there is one if (switches.ContainsKey("cfgfile")) { data["cmdline:cfgfile"] = switches["cfgfile"]; } // If --help is asked for if (switches.ContainsKey("help")) { data["cmdline:showhelp"] = "true"; } return(data); }