diff --git a/Source/Sundew.CommandLine.AcceptanceTests/ArgumentWithDashTests.cs b/Source/Sundew.CommandLine.AcceptanceTests/ArgumentWithDashTests.cs index eb1799a..9621a2d 100644 --- a/Source/Sundew.CommandLine.AcceptanceTests/ArgumentWithDashTests.cs +++ b/Source/Sundew.CommandLine.AcceptanceTests/ArgumentWithDashTests.cs @@ -27,7 +27,7 @@ public void Given_a_commandline_with_an_argument_starting_with_dash_Then_result_ var result = testee.Parse(commandLine); - result.Value.Number.Should().Be(expectedNumber); + result.Value!.Number.Should().Be(expectedNumber); } [Fact] @@ -51,7 +51,7 @@ public void Given_a_commandline_with_arguments_starting_with_dashes_Then_result_ var result = testee.Parse(commandLine); - result.Value.Numbers.Should().Equal(-3, 4, -7); + result.Value!.Numbers.Should().Equal(-3, 4, -7); } [Fact] diff --git a/Source/Sundew.CommandLine.AcceptanceTests/CommandLineBatcher/CommandLineBatcherTests.cs b/Source/Sundew.CommandLine.AcceptanceTests/CommandLineBatcher/CommandLineBatcherTests.cs index 161569c..e2d0ba4 100644 --- a/Source/Sundew.CommandLine.AcceptanceTests/CommandLineBatcher/CommandLineBatcherTests.cs +++ b/Source/Sundew.CommandLine.AcceptanceTests/CommandLineBatcher/CommandLineBatcherTests.cs @@ -42,7 +42,7 @@ public void Parse_When_ChoiceValueIsMissing_Then_BatchArgumentsShouldBeAsExpecte var result = commandLineParser.Parse(string.Empty); result.IsSuccess.Should().BeFalse(); - result.Error.Type.Should().Be(ParserErrorType.RequiredArgumentMissing); + result.Error!.Type.Should().Be(ParserErrorType.RequiredArgumentMissing); result.Error.Message.Should().Be(@"-c/--commands -b/--batches or -bf/--batches-files or -bsi/--batches-stdin"); result.Error.ToString().Should().Be(@"Error: diff --git a/Source/Sundew.CommandLine.AcceptanceTests/EmptyArgumentsTests.cs b/Source/Sundew.CommandLine.AcceptanceTests/EmptyArgumentsTests.cs index ccec5a2..c90d890 100644 --- a/Source/Sundew.CommandLine.AcceptanceTests/EmptyArgumentsTests.cs +++ b/Source/Sundew.CommandLine.AcceptanceTests/EmptyArgumentsTests.cs @@ -16,13 +16,13 @@ public class EmptyArgumentsTests [Theory] [InlineData(null)] [InlineData("")] - public void Given_a_purely_optional_commandline_parsing_null_or_an_empty_string_should_succeed(string commandLine) + public void Given_a_purely_optional_commandline_parsing_null_or_an_empty_string_should_succeed(string? commandLine) { var testee = new CommandLineParser(); testee.WithArguments(new Args(), args => R.Success(args)); var result = testee.Parse(commandLine); - result.Value.IsOn.Should().BeFalse(); + result.Value!.IsOn.Should().BeFalse(); } private class Args : IArguments diff --git a/Source/Sundew.CommandLine.AcceptanceTests/Git/LargeFileSystem/LfsTests.cs b/Source/Sundew.CommandLine.AcceptanceTests/Git/LargeFileSystem/LfsTests.cs index e1b1e52..647e4f7 100644 --- a/Source/Sundew.CommandLine.AcceptanceTests/Git/LargeFileSystem/LfsTests.cs +++ b/Source/Sundew.CommandLine.AcceptanceTests/Git/LargeFileSystem/LfsTests.cs @@ -30,7 +30,7 @@ public void GenerateAndParse_Then_ResultShouldBeExpectedResult() }); var generateResult = commandLineGenerator.Generate(new Lfs(new Track(expectedPattern))); - var parseResult = commandLineParser.Parse(generateResult.Value); + var parseResult = commandLineParser.Parse(generateResult.Value!); parseResult.IsSuccess.Should().BeTrue(); parseResult.Value.Should().Be(expectedResult); @@ -45,7 +45,7 @@ public void Parse_When_VerbIsUnknown_Then_ResultShouldBeExpectedResult() var parseResult = commandLineParser.Parse("lfs adsldasdas"); parseResult.IsSuccess.Should().BeFalse(); - parseResult.Error.Type.Should().Be(ParserErrorType.UnknownVerb); + parseResult.Error!.Type.Should().Be(ParserErrorType.UnknownVerb); } [Fact] @@ -86,7 +86,7 @@ track Start tracking the given patterns(s) through Git LFS. var parseResult = commandLineParser.Parse($"lfs track {helpArgument}"); parseResult.IsSuccess.Should().BeFalse(); - parseResult.Error.Type.Should().Be(ParserErrorType.HelpRequested); + parseResult.Error!.Type.Should().Be(ParserErrorType.HelpRequested); parseResult.Error.Message.Should().Be(expectedHelpText); } diff --git a/Source/Sundew.CommandLine.AcceptanceTests/InvalidConfigurationTests.cs b/Source/Sundew.CommandLine.AcceptanceTests/InvalidConfigurationTests.cs index 9f8c63f..1f5d4f2 100644 --- a/Source/Sundew.CommandLine.AcceptanceTests/InvalidConfigurationTests.cs +++ b/Source/Sundew.CommandLine.AcceptanceTests/InvalidConfigurationTests.cs @@ -21,7 +21,7 @@ public void Parse_When_NoArgumentsNorVerbsAreConfigured_Then_ResultIsSuccessShou var result = testee.Parse("test"); result.IsSuccess.Should().BeFalse(); - result.Error.Type.Should().Be(ParserErrorType.ArgumentsAndVerbsAreNotConfigured); + result.Error!.Type.Should().Be(ParserErrorType.ArgumentsAndVerbsAreNotConfigured); } [Fact] @@ -33,6 +33,6 @@ public void Parse_When_VerbsAreConfiguredButNoArgumentsAndArgumentIsNotAVerb_The var result = testee.Parse("test"); result.IsSuccess.Should().BeFalse(); - result.Error.Type.Should().Be(ParserErrorType.ArgumentsNotConfiguredOrUnknownVerb); + result.Error!.Type.Should().Be(ParserErrorType.ArgumentsNotConfiguredOrUnknownVerb); } } \ No newline at end of file diff --git a/Source/Sundew.CommandLine.AcceptanceTests/InvalidOptionTests.cs b/Source/Sundew.CommandLine.AcceptanceTests/InvalidOptionTests.cs index d9ef2ab..4c77ee7 100644 --- a/Source/Sundew.CommandLine.AcceptanceTests/InvalidOptionTests.cs +++ b/Source/Sundew.CommandLine.AcceptanceTests/InvalidOptionTests.cs @@ -24,7 +24,7 @@ public void Parse_When_InvalidOptionIsSpecified_Then_ResultShouldBeFalseAndError var result = testee.Parse(commandLine); result.IsSuccess.Should().BeFalse(); - result.Error.Type.Should().Be(ParserErrorType.UnknownOption); + result.Error!.Type.Should().Be(ParserErrorType.UnknownOption); result.Error.Message.Should().Be(@"The option does not exist: -d"); } @@ -39,7 +39,7 @@ public void Parse_When_UnknownOptionIsSpecified_Then_ResultShouldBeFalseAndError var result = testee.Parse(commandLine); result.IsSuccess.Should().BeFalse(); - result.Error.Type.Should().Be(ParserErrorType.UnknownOption); + result.Error!.Type.Should().Be(ParserErrorType.UnknownOption); result.Error.Message.Should().Be(@"The option does not exist: -d"); } diff --git a/Source/Sundew.CommandLine.AcceptanceTests/Samples/Aupli/AupliCommandLineTests.cs b/Source/Sundew.CommandLine.AcceptanceTests/Samples/Aupli/AupliCommandLineTests.cs index 0b258b4..8d79521 100644 --- a/Source/Sundew.CommandLine.AcceptanceTests/Samples/Aupli/AupliCommandLineTests.cs +++ b/Source/Sundew.CommandLine.AcceptanceTests/Samples/Aupli/AupliCommandLineTests.cs @@ -28,7 +28,7 @@ public void Given_a_commandline_with_a_complex_type_Then_the_complex_type_should var result = commandLineParser.Parse(commandLine); result.IsSuccess.Should().BeTrue(); - result.Value.AllowShutdown.Should().BeTrue(); + result.Value!.AllowShutdown.Should().BeTrue(); result.Value.IsLoggingToConsole.Should().BeTrue(); result.Value.FileLogOptions?.LogPath.Should().Be(ExpectedLogPath); result.Value.FileLogOptions?.MaxLogFileSizeInBytes.Should().Be(ExpectedMaxLogFileSizeInBytes); @@ -46,7 +46,7 @@ public void Given_a_commandline_with_an_optional_complex_type_with_a_required_fi var result = commandLineParser.Parse(commandLine); result.IsSuccess.Should().BeFalse(); - result.Error.Type.Should().Be(ParserErrorType.InnerParserError); + result.Error!.Type.Should().Be(ParserErrorType.InnerParserError); result.Error.InnerParserError!.Type.Should().Be(ParserErrorType.RequiredArgumentMissing); } @@ -137,7 +137,7 @@ public void Given_the_help_commandline_Then_ResultErrorToString_should_be_the_ex commandLineParser.WithArguments(new Options(false, false), options => R.Success(options)); var parserResult = commandLineParser.Parse("-?"); - var result = parserResult.Error.ToString(); + var result = parserResult.Error!.ToString(); result.Should().Be(expectedHelpText); } @@ -151,7 +151,7 @@ public void Given_a_commandline_without_a_required_argument_Then_ResultErrorToSt commandLineParser.WithArguments(new Options(false, false), options => R.Success(options)); var parserResult = commandLineParser.Parse($@"-fl """""); - var result = parserResult.Error.ToString(); + var result = parserResult.Error!.ToString(); result.Should().Be(expectedText); } @@ -167,7 +167,7 @@ public void Given_a_nested_commandline_without_a_required_argument_Then_ResultEr commandLineParser.WithArguments(new Options(false, false), options => R.Success(options)); var parserResult = commandLineParser.Parse($@"-fl -ms 3"); - var result = parserResult.Error.ToString(); + var result = parserResult.Error!.ToString(); result.Should().Be(expectedText); } @@ -181,7 +181,7 @@ public void Given_a_commandline_with_an_option_without_an_argument_Then_ResultEr commandLineParser.WithArguments(new FileLogOptions(string.Empty), options => R.Success(options)); var parserResult = commandLineParser.Parse($@"-lp"); - var result = parserResult.Error.ToString(); + var result = parserResult.Error!.ToString(); result.Should().Be(expectedText); } @@ -211,7 +211,7 @@ public void Given_a_commandline_When_parsing_twice_Then_ResultErrorToString_shou var result = commandLineParser.Parse($@"-lp ""{expectedLogPath}"""); - result.Value.LogPath.Should().Be(expectedLogPath); + result.Value!.LogPath.Should().Be(expectedLogPath); result.Value.MaxLogFileSizeInBytes.Should().NotBe(ExpectedMaxLogFileSizeInBytes); result.Value.MaxNumberOfLogFiles.Should().Be(expectedMaxFiles); } diff --git a/Source/Sundew.CommandLine.AcceptanceTests/Samples/KuandoBusylightForTeamCity/KuandoBusylightForTeamCityTests.cs b/Source/Sundew.CommandLine.AcceptanceTests/Samples/KuandoBusylightForTeamCity/KuandoBusylightForTeamCityTests.cs index b8ebbbf..c399426 100644 --- a/Source/Sundew.CommandLine.AcceptanceTests/Samples/KuandoBusylightForTeamCity/KuandoBusylightForTeamCityTests.cs +++ b/Source/Sundew.CommandLine.AcceptanceTests/Samples/KuandoBusylightForTeamCity/KuandoBusylightForTeamCityTests.cs @@ -30,7 +30,7 @@ public void Given_a_complete_commandline_Then_parsed_result_should_be_expected_v var result = testee.Parse(commandLine); result.IsSuccess.Should().BeTrue(); - result.Value.HostName.Should().Be(ExpectedHost); + result.Value!.HostName.Should().Be(ExpectedHost); result.Value.BuildTypeId.Should().Be(ExpectedBuildTypeId); result.Value.Credentials?.UserName.Should().Be(ExpectedUserName); new NetworkCredential(string.Empty, result.Value.Credentials?.Password).Password.Should().Be(ExpectedPassword); diff --git a/Source/Sundew.CommandLine.AcceptanceTests/Sundew.CommandLine.AcceptanceTests.csproj b/Source/Sundew.CommandLine.AcceptanceTests/Sundew.CommandLine.AcceptanceTests.csproj index 91312db..61f34b1 100644 --- a/Source/Sundew.CommandLine.AcceptanceTests/Sundew.CommandLine.AcceptanceTests.csproj +++ b/Source/Sundew.CommandLine.AcceptanceTests/Sundew.CommandLine.AcceptanceTests.csproj @@ -20,15 +20,15 @@ - - - + + + all runtime; build; native; contentfiles; analyzers - - + + all runtime; build; native; contentfiles; analyzers diff --git a/Source/Sundew.CommandLine.AcceptanceTests/VerbWithoutArgumentTests.cs b/Source/Sundew.CommandLine.AcceptanceTests/VerbWithoutArgumentTests.cs index 58e2618..8f11ac2 100644 --- a/Source/Sundew.CommandLine.AcceptanceTests/VerbWithoutArgumentTests.cs +++ b/Source/Sundew.CommandLine.AcceptanceTests/VerbWithoutArgumentTests.cs @@ -24,6 +24,6 @@ public void Given_a_commandline_that_only_contains_verbs_When_parsed_with_a_verb var result = commandLineParser.Parse(new[] { "run", "and", "fail" }); result.IsSuccess.Should().BeFalse(); - result.Error.Type.Should().Be(ParserErrorType.UnknownVerb); + result.Error!.Type.Should().Be(ParserErrorType.UnknownVerb); } } \ No newline at end of file diff --git a/Source/Sundew.CommandLine.UnitTests/Sundew.CommandLine.UnitTests.csproj b/Source/Sundew.CommandLine.UnitTests/Sundew.CommandLine.UnitTests.csproj index f3c1937..325e1f0 100644 --- a/Source/Sundew.CommandLine.UnitTests/Sundew.CommandLine.UnitTests.csproj +++ b/Source/Sundew.CommandLine.UnitTests/Sundew.CommandLine.UnitTests.csproj @@ -17,14 +17,14 @@ - - + + all runtime; build; native; contentfiles; analyzers - - + + all runtime; build; native; contentfiles; analyzers diff --git a/Source/Sundew.CommandLine/CommandLineParser{TSuccess,TError}.cs b/Source/Sundew.CommandLine/CommandLineParser{TSuccess,TError}.cs index bb10d0d..ac77a62 100644 --- a/Source/Sundew.CommandLine/CommandLineParser{TSuccess,TError}.cs +++ b/Source/Sundew.CommandLine/CommandLineParser{TSuccess,TError}.cs @@ -157,7 +157,7 @@ public ValueTask>> ParseAsync(IReadOnlyListParses the specified arguments. /// The arguments. /// The parser result. - public ValueTask>> ParseAsync(string arguments) + public ValueTask>> ParseAsync(string? arguments) { return this.ParseAsync(arguments, 0); } @@ -168,7 +168,7 @@ public ValueTask>> ParseAsync(string arguments) /// The arguments. /// The argument index at which to start parsing. /// The parser result. - public ValueTask>> ParseAsync(string arguments, int startIndex) + public ValueTask>> ParseAsync(string? arguments, int startIndex) { var argumentArray = arguments.AsMemory().ParseCommandLineArguments().ToArray(); return this.ParseAsync(argumentArray, startIndex); @@ -264,7 +264,7 @@ public R> Parse(IReadOnlyList /// Parses the specified arguments. /// The arguments. /// The parser result. - public R> Parse(string arguments) + public R> Parse(string? arguments) { return this.Parse(arguments, 0); } @@ -275,7 +275,7 @@ public R> Parse(string arguments) /// The arguments. /// The argument index at which to start parsing. /// The parser result. - public R> Parse(string arguments, int startIndex) + public R> Parse(string? arguments, int startIndex) { var argumentArray = arguments.AsMemory().ParseCommandLineArguments().ToArray(); return this.Parse(argumentArray, startIndex); @@ -320,7 +320,7 @@ private static R> CheckResultForHelpRequestedError ArgumentsAction? argumentsAction, Settings settings) { - if (!result) + if (!result.IsSuccess) { if (result.Error.Type == ParserErrorType.HelpRequested) { diff --git a/Source/Sundew.CommandLine/Internal/CommandLineArgumentsGenerator.cs b/Source/Sundew.CommandLine/Internal/CommandLineArgumentsGenerator.cs index 39ea252..4f68002 100644 --- a/Source/Sundew.CommandLine/Internal/CommandLineArgumentsGenerator.cs +++ b/Source/Sundew.CommandLine/Internal/CommandLineArgumentsGenerator.cs @@ -26,7 +26,7 @@ public static R Generate(IArguments arguments, StringBuilder str foreach (var option in argumentsBuilder.Options) { var serializeResult = option.SerializeTo(stringBuilder, settings, useAliases); - if (!serializeResult) + if (serializeResult.HasError) { return R.Error(serializeResult.Error); } diff --git a/Source/Sundew.CommandLine/Internal/Options/NestingOption.cs b/Source/Sundew.CommandLine/Internal/Options/NestingOption.cs index f287dbe..604b132 100644 --- a/Source/Sundew.CommandLine/Internal/Options/NestingOption.cs +++ b/Source/Sundew.CommandLine/Internal/Options/NestingOption.cs @@ -75,7 +75,7 @@ public R SerializeTo(StringBuilder stringBuilder, Settings stringBuilder.Append(Constants.SpaceCharacter); var result = SerializeValue(actualOption, stringBuilder, settings, useAliases); - if (result) + if (result.IsSuccess) { return result.To(true); } @@ -108,7 +108,7 @@ public R DeserializeFrom( { var options = this.getDefault(); var result = this.DeserializeValue(commandLineArgumentsParser, argumentList, options, settings); - if (result) + if (result.IsSuccess) { this.setOptions(options); return result; diff --git a/Source/Sundew.CommandLine/ResultExtensions.cs b/Source/Sundew.CommandLine/ResultExtensions.cs index 0122fc2..ebf8315 100644 --- a/Source/Sundew.CommandLine/ResultExtensions.cs +++ b/Source/Sundew.CommandLine/ResultExtensions.cs @@ -20,7 +20,7 @@ public static class ResultExtensions /// A value indicating whether help could be useful. public static bool WriteToConsole(this R> result) { - if (result) + if (result.IsSuccess) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(result.Value); @@ -45,7 +45,7 @@ public static bool WriteToConsole(this RThe exit code. public static int GetExitCode(this R> result) { - if (result) + if (result.IsSuccess) { return result.Value; } diff --git a/Source/Sundew.CommandLine/Sundew.CommandLine.csproj b/Source/Sundew.CommandLine/Sundew.CommandLine.csproj index 02dce07..21a0666 100644 --- a/Source/Sundew.CommandLine/Sundew.CommandLine.csproj +++ b/Source/Sundew.CommandLine/Sundew.CommandLine.csproj @@ -35,12 +35,18 @@ Features: SA1625 + + + + + + - + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -52,18 +58,14 @@ Features: all runtime; build; native; contentfiles; analyzers - - - - + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - \ No newline at end of file