private static bool TryGetPhase(int originalArgCount, IEnumerable <ArgumentInstance> arguments, ILogger logger, out AnalysisPhase phase) { // The command line parser will already have checked for duplicates ArgumentInstance argumentInstance; bool hasBeginVerb = ArgumentInstance.TryGetArgument(BeginId, arguments, out argumentInstance); bool hasEndVerb = ArgumentInstance.TryGetArgument(EndId, arguments, out argumentInstance); if (hasBeginVerb && hasEndVerb) // both { phase = AnalysisPhase.Unspecified; logger.LogError(Resources.ERROR_CmdLine_BothBeginAndEndSupplied); } else if (!hasBeginVerb && !hasEndVerb) // neither { // Backwards compatibility - decide the phase based on the number of arguments passed phase = originalArgCount == 0 ? AnalysisPhase.PostProcessing : AnalysisPhase.PreProcessing; logger.LogWarning(Resources.WARN_CmdLine_v09_Compat); } else // begin or end { phase = hasBeginVerb ? AnalysisPhase.PreProcessing : AnalysisPhase.PostProcessing; } return(phase != AnalysisPhase.Unspecified); }
public void TryGetArgument_WhenArgumentsIsNull_ThrowsArgumentNullException() { // Arrange Action action = () => ArgumentInstance.TryGetArgument("foo", null, out var instance); // Assert action.ShouldThrowExactly <ArgumentNullException>().And.ParamName.Should().Be("arguments"); }
public void TryGetArgument_WhenIdIsWhitespaces_ThrowsArgumentNullException() { // Arrange Action action = () => ArgumentInstance.TryGetArgument(" ", Enumerable.Empty <ArgumentInstance>(), out var instance); // Assert action.ShouldThrowExactly <ArgumentNullException>().And.ParamName.Should().Be("id"); }
private bool TryParseAnalyzerRef(IEnumerable<ArgumentInstance> arguments, out NuGetReference analyzerRef) { analyzerRef = null; ArgumentInstance analyzerArg = arguments.SingleOrDefault(a => ArgumentDescriptor.IdComparer.Equals(KeywordIds.AnalyzerRef, a.Descriptor.Id)); if (analyzerArg != null) { analyzerRef = TryParseNuGetReference(analyzerArg.Value); } return analyzerRef != null; }
private string GetOutputDirectory(IEnumerable <ArgumentInstance> arguments) { ArgumentInstance arg = arguments.SingleOrDefault(a => ArgumentDescriptor.IdComparer.Equals(KeywordIds.OutputDirectory, a.Descriptor.Id)); if (arg != null) { return(arg.Value); } return(Directory.GetCurrentDirectory()); }
private static void AssertExpectedValue(string id, string expectedValue, IEnumerable <ArgumentInstance> actual) { bool found = ArgumentInstance.TryGetArgument(id, actual, out ArgumentInstance actualInstance); Assert.IsTrue(found, "Expected argument was not found. Id: {0}", id); Assert.IsNotNull(actual); Assert.AreEqual(expectedValue, actualInstance.Value, "Unexpected instance value. Id: {0}", id); string[] actualValues = actual.Where(a => ArgumentDescriptor.IdComparer.Equals(a.Descriptor.Id, id)).Select(a => a.Value).ToArray(); Assert.AreEqual(1, actualValues.Length, "Not expecting to find multiple values. Id: {0}", id); }
private bool TryParseSqaleArgument(IEnumerable <ArgumentInstance> arguments) { ArgumentInstance arg = arguments.SingleOrDefault(a => ArgumentDescriptor.IdComparer.Equals(KeywordIds.SqaleXmlFile, a.Descriptor.Id)); if (arg == null) { return(true); } logger.LogError(CmdLineResources.ERROR_SqaleParameterIsNotSupported); return(false); }
private static void AssertExpectedValue(string id, string expectedValue, IEnumerable <ArgumentInstance> actual) { var found = ArgumentInstance.TryGetArgument(id, actual, out var actualInstance); found.Should().BeTrue("Expected argument was not found. Id: {0}", id); actual.Should().NotBeNull(); actualInstance.Value.Should().Be(expectedValue, "Unexpected instance value. Id: {0}", id); var actualValues = actual.Where(a => ArgumentDescriptor.IdComparer.Equals(a.Descriptor.Id, id)).Select(a => a.Value).ToArray(); actualValues.Length.Should().Be(1, "Not expecting to find multiple values. Id: {0}", id); }
private static bool TryGetInstallTargetsEnabled(IEnumerable <ArgumentInstance> arguments, ILogger logger, out bool installTargetsEnabled) { var hasInstallTargetsVerb = ArgumentInstance.TryGetArgument(KeywordIds.InstallLoaderTargets, arguments, out ArgumentInstance argumentInstance); if (hasInstallTargetsVerb) { var canParse = bool.TryParse(argumentInstance.Value, out installTargetsEnabled); if (!canParse) { logger.LogError(Resources.ERROR_CmdLine_InvalidInstallTargetsValue, argumentInstance.Value); return(false); } } else { installTargetsEnabled = TargetsInstaller.DefaultInstallSetting; } return(true); }
private bool TryParseSqaleFile(IEnumerable<ArgumentInstance> arguments, out string sqaleFilePath) { bool sucess = true; sqaleFilePath = null; ArgumentInstance arg = arguments.SingleOrDefault(a => ArgumentDescriptor.IdComparer.Equals(KeywordIds.SqaleXmlFile, a.Descriptor.Id)); if (arg != null) { if (File.Exists(arg.Value)) { sqaleFilePath = arg.Value; this.logger.LogDebug(CmdLineResources.DEBUG_UsingSqaleFile, sqaleFilePath); } else { sucess = false; this.logger.LogError(CmdLineResources.ERROR_SqaleFileNotFound, arg.Value); } } return sucess; }
private static string GetArgumentValue(string id, IEnumerable <ArgumentInstance> arguments) { ArgumentInstance argument = arguments.Single(a => a.Descriptor.Id == id); return(argument.Value); }
private static string GetOutputDirectory(IEnumerable<ArgumentInstance> arguments) { ArgumentInstance arg = arguments.SingleOrDefault(a => ArgumentDescriptor.IdComparer.Equals(KeywordIds.OutputDirectory, a.Descriptor.Id)); return arg?.Value; }
private static bool GetRecursion(IEnumerable<ArgumentInstance> arguments) { ArgumentInstance arg = arguments.SingleOrDefault(a => ArgumentDescriptor.IdComparer.Equals(KeywordIds.RecurseDependencies, a.Descriptor.Id)); return arg != null; }
private static bool GetLicenseAcceptance(IEnumerable<ArgumentInstance> arguments) { ArgumentInstance arg = arguments.SingleOrDefault(a => ArgumentDescriptor.IdComparer.Equals(KeywordIds.AcceptLicenses, a.Descriptor.Id)); return arg != null; }
private string GetNuGetRepository(IEnumerable <ArgumentInstance> arguments) { ArgumentInstance arg = arguments.SingleOrDefault(a => ArgumentDescriptor.IdComparer.Equals(KeywordIds.CustomNuGetRepository, a.Descriptor.Id)); return(arg?.Value); }