static void Convert(CommandArguments args) { // input IEnumerable <TestReportBase> testReports = ReadInput(args); // output - none if (args.OutputFormats == OutputFormats.None) { ProgramExit.Exit(ExitCode.UnknownOutputFormat, true); return; } // output - junit if ((args.OutputFormats & OutputFormats.JUnit) == OutputFormats.JUnit) { // the output JUnit path must be NOT an exist directory if (Directory.Exists(args.JUnitXmlFile)) { OutputWriter.WriteLine(Properties.Resources.ErrMsg_JUnit_OutputCannotDir); ProgramExit.Exit(ExitCode.InvalidArgument); return; } // if not an aggregation report output, then only convert for the first report if (!args.Aggregation) { TestReportBase testReport = testReports.First(); if (testReport == null) { ProgramExit.Exit(ExitCode.CannotReadFile); return; } // the output JUnit file path must be NOT same as the input file FileInfo fiInput = new FileInfo(testReport.ReportFile); FileInfo fiOutput = new FileInfo(args.JUnitXmlFile); if (fiInput.FullName == fiOutput.FullName) { OutputWriter.WriteLine(Properties.Resources.ErrMsg_JUnit_OutputSameAsInput); ProgramExit.Exit(ExitCode.InvalidArgument); return; } // convert if (!JUnit.Converter.ConvertAndSave(args, testReport)) { ProgramExit.Exit(ExitCode.GeneralError); } else { OutputWriter.WriteLine(Properties.Resources.InfoMsg_JUnit_OutputGenerated, fiOutput.FullName); } } else { // an aggregation report output if (!JUnit.Converter.ConvertAndSaveAggregation(args, testReports)) { ProgramExit.Exit(ExitCode.GeneralError); } else { FileInfo fiOutput = new FileInfo(args.JUnitXmlFile); OutputWriter.WriteLine(Properties.Resources.InfoMsg_JUnit_OutputGenerated, fiOutput.FullName); } } } // output - nunit 3 if ((args.OutputFormats & OutputFormats.NUnit3) == OutputFormats.NUnit3) { } }
public CommandArguments ParseCommandArguments(string[] args, out string[] errors) { List <string> errorList = new List <string>(); CommandArguments cmdArgs = new CommandArguments(); int pos = -1; for (int i = 0; i < args.Length; i++) { string arg = args[i]; if (IsOptionalArgument(arg)) { // optional argument bool isRecognized = false; foreach (OptArgInfo optArg in _optArgs) { if (IsOptionalArgument(arg, optArg.Argument.Names)) { isRecognized = true; Type propertyType = optArg.PropertyInfo.PropertyType; if (propertyType == typeof(bool)) { optArg.PropertyInfo.SetValue(cmdArgs, true); break; } else if (propertyType == typeof(string)) { i++; if (i >= args.Length) { errorList.Add(string.Format(Properties.Resources.ErrorMsg_MissingOptionalArgValue, optArg.Argument.FirstName)); } else { optArg.PropertyInfo.SetValue(cmdArgs, args[i]); } break; } else { // not supported property type errorList.Add(string.Format(Properties.Resources.ErrorMsg_UnknownArgPropertyType, optArg.Argument.FirstName, propertyType.FullName)); } } } if (!isRecognized) { errorList.Add(string.Format(Properties.Resources.WarningMsg_UnknownOption, arg)); } } else { // positional argument cmdArgs.AllPositionalArgs.Add(arg); pos++; if (pos < _posArgs.Count) { PosArgInfo posArg = _posArgs[pos]; posArg.PropertyInfo.SetValue(cmdArgs, arg); } } } errors = errorList.ToArray(); return(cmdArgs); }