static ReturnCode ParseOptions([NotNull] string[] args) { if (args == null) { throw new ArgumentNullException("args"); } string importerList = MapUtility.GetImporters().JoinToString(c => c.Format.ToString()); string exporterList = MapUtility.GetExporters().JoinToString(c => c.Format.ToString()); bool printHelp = false; opts = new OptionSet() .Add("e=|exporter=", "REQUIRED: Converter used for exporting/saving maps. " + "Available exporters: " + exporterList, o => exporterName = o) .Add("f=|filter=", "Optional: Pattern to filter input filenames, e.g. \"*.dat\" or \"builder*\". " + "Applicable only when a directory name is given as input.", o => inputFilter = o) .Add("i=|importer=", "Optional: Converter used for importing/loading maps. " + "Available importers: Auto (default), " + importerList, o => importerName = o) .Add("o=|output=", "Optional: Path to save converted map files to. " + "If not specified, converted maps will be saved to the original maps' directory.", o => outputDirName = o) .Add("r|recursive", "Optional: Look through all subdirectories, and convert map files there too. " + "Applicable only when a directory name is given as input.", o => recursive = (o != null)) .Add("t|tryhard", "Try ALL the map converters on map files that cannot be loaded normally.", o => tryHard = (o != null)) .Add("x|regex", "Enable regular expessions in \"filter\".", o => useRegex = (o != null)) .Add("y|overwrite", "Optional: Do not ask for confirmation to overwrite existing files.", o => overwrite = (o != null)) .Add("?|help|h", "Prints usage information and a list of options.", o => printHelp = (o != null)); List <string> pathList; try { pathList = opts.Parse(args); } catch (OptionException ex) { Console.Error.Write("MapConverter: "); Console.Error.WriteLine(ex.Message); PrintHelp(); return(ReturnCode.ArgumentError); } // Print help and break out if (printHelp) { PrintHelp(); Environment.Exit((int)ReturnCode.Success); } if (pathList.Count != 1) { Console.Error.WriteLine("MapConverter: At least one file or directory name required."); PrintUsage(); return(ReturnCode.ArgumentError); } inputPathList = pathList.ToArray(); if (exporterName == null) { Console.Error.WriteLine("MapConverter: Export format required."); PrintUsage(); return(ReturnCode.ArgumentError); } outputDirGiven = (outputDirName != null); return(ReturnCode.Success); }