//idea is to check output args which are not applicable to NuGet callers before the command operation is run for max efficiency private static int VerifyOutputArgsRun(CLITagDiffCmdOptions options) { loggerFactory = options.GetLoggerFactory(); CommonOutputChecks(options); return(RunTagDiffCommand(options)); }
private static CommandResultsWriter GetTagDiffWriter(CLITagDiffCmdOptions options) { CommandResultsWriter?writer; switch (options.OutputFileFormat.ToLower()) { case "_dummy": writer = new TagDiffDummyWriter(); break; case "json": writer = new JsonWriter(); break; case "text": writer = new TagDiffTextWriter(); break; default: WriteOnce.Error(MsgHelp.FormatString(MsgHelp.ID.CMD_INVALID_ARG_VALUE, "-f")); throw new OpException((MsgHelp.FormatString(MsgHelp.ID.CMD_INVALID_ARG_VALUE, "-f"))); } //assign the stream as a file or console writer.OutputFileName = options.OutputFilePath; writer.TextWriter = GetTextWriter(writer.OutputFileName); return(writer); }
private static int RunTagDiffCommand(CLITagDiffCmdOptions cliOptions) { TagDiffCommand command = new(new TagDiffOptions() { SourcePath1 = cliOptions.SourcePath1, SourcePath2 = cliOptions.SourcePath2, CustomRulesPath = cliOptions.CustomRulesPath, CustomCommentsPath = cliOptions.CustomCommentsPath, CustomLanguagesPath = cliOptions.CustomLanguagesPath, IgnoreDefaultRules = cliOptions.IgnoreDefaultRules, FilePathExclusions = cliOptions.FilePathExclusions, TestType = cliOptions.TestType, ConfidenceFilters = cliOptions.ConfidenceFilters, SeverityFilters = cliOptions.SeverityFilters, FileTimeOut = cliOptions.FileTimeOut, ProcessingTimeOut = cliOptions.ProcessingTimeOut, ScanUnknownTypes = cliOptions.ScanUnknownTypes, SingleThread = cliOptions.SingleThread, }, loggerFactory); TagDiffResult tagDiffResult = command.GetResult(); ResultsWriter writer = new(loggerFactory); writer.Write(tagDiffResult, cliOptions); return((int)tagDiffResult.ResultCode); }
private static int RunTagDiffCommand(CLITagDiffCmdOptions cliOptions) { TagDiffCommand command = new(new TagDiffOptions() { SourcePath1 = cliOptions.SourcePath1, SourcePath2 = cliOptions.SourcePath2, CustomRulesPath = cliOptions.CustomRulesPath, IgnoreDefaultRules = cliOptions.IgnoreDefaultRules, FilePathExclusions = cliOptions.FilePathExclusions, ConsoleVerbosityLevel = cliOptions.ConsoleVerbosityLevel, TestType = cliOptions.TestType, Log = cliOptions.Log, ConfidenceFilters = cliOptions.ConfidenceFilters, FileTimeOut = cliOptions.FileTimeOut, ProcessingTimeOut = cliOptions.ProcessingTimeOut, ScanUnknownTypes = cliOptions.ScanUnknownTypes, SingleThread = cliOptions.SingleThread, LogFilePath = cliOptions.LogFilePath, LogFileLevel = cliOptions.LogFileLevel }); TagDiffResult tagDiffResult = command.GetResult(); ResultsWriter.Write(tagDiffResult, cliOptions); return((int)tagDiffResult.ResultCode); }
public override void WriteResults(Result result, CLICommandOptions commandOptions, bool autoClose = true) { TagDiffResult tagDiffResult = (TagDiffResult)result; CLITagDiffCmdOptions cLITagDiffCmdOptions = (CLITagDiffCmdOptions)commandOptions; TextWriter.WriteLine(MsgHelp.FormatString(MsgHelp.ID.TAGTEST_RESULTS_TEST_TYPE, cLITagDiffCmdOptions.TestType)); if (tagDiffResult.ResultCode == TagDiffResult.ExitCode.TestFailed) { TextWriter.WriteLine(MsgHelp.GetString(MsgHelp.ID.TAGTEST_RESULTS_FAIL)); } else { TextWriter.WriteLine(MsgHelp.GetString(MsgHelp.ID.TAGTEST_RESULTS_SUCCESS)); } //Results list if (tagDiffResult.TagDiffList.Count > 0) { TextWriter.WriteLine("Differences"); foreach (TagDiff tagDiff in tagDiffResult.TagDiffList) { TextWriter.WriteLine(string.Format("Tag: {0}, Only found in file: {1}", tagDiff.Tag, tagDiff.Source)); } } if (autoClose) { FlushAndClose(); } }
//idea is to check output args which are not applicable to NuGet callers before the command operation is run for max efficiency private static int VerifyOutputArgsRun(CLITagDiffCmdOptions options) { Logger logger = Utils.SetupLogging(options, true); WriteOnce.Log = logger; options.Log = logger; CommonOutputChecks(options); return(RunTagDiffCommand(options)); }
/// <summary> /// Responsible for returning the correct cmd and format writer for output of cmd results. An an output /// file will be opened as a stream if provided otherwise the console.out stream is used /// A downcast is expected as the input param containing the common output format and filepath for simplifying /// the allocation to a single method and serves as a type selector but is also recast for command specific /// options in the writer as needed /// </summary> /// <param name="options"></param> /// <returns></returns> public CommandResultsWriter GetWriter(CLICommandOptions options) { return(options switch { CLIAnalyzeCmdOptions cliAnalyzeCmdOptions => GetAnalyzeWriter(cliAnalyzeCmdOptions), CLITagDiffCmdOptions cliTagDiffCmdOptions => GetTagDiffWriter(cliTagDiffCmdOptions), CLIExportTagsCmdOptions cliExportTagsCmdOptions => GetExportTagsWriter(cliExportTagsCmdOptions), CLIVerifyRulesCmdOptions cliVerifyRulesCmdOptions => GetVerifyRulesWriter(cliVerifyRulesCmdOptions), CLIPackRulesCmdOptions cliPackRulesCmdOptions => GetPackRulesWriter(cliPackRulesCmdOptions), _ => throw new OpException($"Unrecognized object type {options.GetType().Name} in writer request") });
public override void WriteResults(Result result, CLICommandOptions commandOptions, bool autoClose = true) { TagDiffResult tagDiffResult = (TagDiffResult)result; CLITagDiffCmdOptions cLITagDiffCmdOptions = (CLITagDiffCmdOptions)commandOptions; //For console output, update write once for same results to console or file WriteOnce.TextWriter = TextWriter; if (string.IsNullOrEmpty(commandOptions.OutputFilePath)) { WriteOnce.Result("Results"); } WriteOnce.General(MsgHelp.FormatString(MsgHelp.ID.TAGTEST_RESULTS_TEST_TYPE, cLITagDiffCmdOptions.TestType), false, WriteOnce.ConsoleVerbosity.Low); if (tagDiffResult.ResultCode == TagDiffResult.ExitCode.TestFailed) { WriteOnce.Any(MsgHelp.GetString(MsgHelp.ID.TAGTEST_RESULTS_FAIL), true, ConsoleColor.Red, WriteOnce.ConsoleVerbosity.Low); } else { WriteOnce.Any(MsgHelp.GetString(MsgHelp.ID.TAGTEST_RESULTS_SUCCESS), true, ConsoleColor.Green, WriteOnce.ConsoleVerbosity.Low); } //Results list if (tagDiffResult.TagDiffList.Count > 0) { WriteOnce.Result("Differences"); foreach (TagDiff tagDiff in tagDiffResult.TagDiffList) { WriteOnce.General(string.Format("Tag: {0}, Only found in file: {1}", tagDiff.Tag, tagDiff.Source)); } } if (autoClose) { FlushAndClose(); } }
private static int RunTagDiffCommand(CLITagDiffCmdOptions cliOptions) { TagDiffResult.ExitCode exitCode = TagDiffResult.ExitCode.CriticalError; TagDiffCommand command = new TagDiffCommand(new TagDiffOptions() { SourcePath1 = cliOptions.SourcePath1 ?? "", SourcePath2 = cliOptions.SourcePath2 ?? "", CustomRulesPath = cliOptions.CustomRulesPath, IgnoreDefaultRules = cliOptions.IgnoreDefaultRules, FilePathExclusions = cliOptions.FilePathExclusions, ConsoleVerbosityLevel = cliOptions.ConsoleVerbosityLevel, TestType = cliOptions.TestType, Log = cliOptions.Log }); TagDiffResult tagDiffResult = command.GetResult(); exitCode = tagDiffResult.ResultCode; ResultsWriter.Write(tagDiffResult, cliOptions); return((int)exitCode); }