From 1da075298035071b75554489aaa641b3be02376b Mon Sep 17 00:00:00 2001 From: Advay Tandon Date: Wed, 5 Jun 2024 19:23:34 -0700 Subject: [PATCH 1/2] Add dotnet nuget why command --- .../dotnet-nuget/NuGetCommandParser.cs | 15 +++++++++++++ .../GivenANuGetCommand.cs | 3 +++ .../CommandTests/CompleteCommandTests.cs | 21 ++++++++++++++++++- 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/Cli/dotnet/commands/dotnet-nuget/NuGetCommandParser.cs b/src/Cli/dotnet/commands/dotnet-nuget/NuGetCommandParser.cs index 8fe864d8ce0f..9d17a593aaa2 100644 --- a/src/Cli/dotnet/commands/dotnet-nuget/NuGetCommandParser.cs +++ b/src/Cli/dotnet/commands/dotnet-nuget/NuGetCommandParser.cs @@ -35,6 +35,7 @@ private static CliCommand ConstructCommand() command.Subcommands.Add(GetVerifyCommand()); command.Subcommands.Add(GetTrustCommand()); command.Subcommands.Add(GetSignCommand()); + command.Subcommands.Add(GetWhyCommand()); command.SetAction(NuGetCommand.Run); @@ -213,5 +214,19 @@ private static CliCommand GetSignCommand() return signCommand; } + + private static CliCommand GetWhyCommand() + { + CliCommand whyCommand = new("why"); + + whyCommand.Arguments.Add(new CliArgument("PROJECT|SOLUTION") { Arity = ArgumentArity.ExactlyOne }); + whyCommand.Arguments.Add(new CliArgument("PACKAGE") { Arity = ArgumentArity.ExactlyOne }); + + whyCommand.Options.Add(new CliOption("--framework", "-f") { Arity = ArgumentArity.OneOrMore }); + + whyCommand.SetAction(NuGetCommand.Run); + + return whyCommand; + } } } diff --git a/src/Tests/dotnet-nuget.UnitTests/GivenANuGetCommand.cs b/src/Tests/dotnet-nuget.UnitTests/GivenANuGetCommand.cs index b405aa74e257..02080bc9c0a1 100644 --- a/src/Tests/dotnet-nuget.UnitTests/GivenANuGetCommand.cs +++ b/src/Tests/dotnet-nuget.UnitTests/GivenANuGetCommand.cs @@ -75,6 +75,9 @@ public GivenANuGetCommand(ITestOutputHelper log) : base(log) "--interactive", "--verbosity", "detailed", "--format", "json"}, 0)] + [InlineData(new[] { "why" }, 0)] + [InlineData(new[] { "why", "C:\\path", "Fake.Package" }, 0)] + [InlineData(new[] { "why", "C:\\path", "Fake.Package", "--framework", "net472", "-f", "netcoreapp5.0" }, 0)] public void ItPassesCommandIfSupported(string[] inputArgs, int result) { diff --git a/src/Tests/dotnet.Tests/CommandTests/CompleteCommandTests.cs b/src/Tests/dotnet.Tests/CommandTests/CompleteCommandTests.cs index a895374c1802..4cc23ba5c6c8 100644 --- a/src/Tests/dotnet.Tests/CommandTests/CompleteCommandTests.cs +++ b/src/Tests/dotnet.Tests/CommandTests/CompleteCommandTests.cs @@ -118,7 +118,8 @@ public void GivenNuGetCommandItDisplaysCompletions() "push", "verify", "trust", - "sign" + "sign", + "why" }; var reporter = new BufferedReporter(); @@ -286,6 +287,24 @@ public void GivenNuGetSignCommandItDisplaysCompletions() reporter.Lines.OrderBy(c => c).Should().Equal(expected.OrderBy(c => c)); } + [Fact] + public void GivenNuGetWhyCommandItDisplaysCompletions() + { + var expected = new[] { + "--framework", + "--help", + "-?", + "-f", + "-h", + "/?", + "/h" + }; + + var reporter = new BufferedReporter(); + CompleteCommand.RunWithReporter(new[] { "dotnet nuget why " }, reporter).Should().Be(0); + reporter.Lines.OrderBy(c => c).Should().Equal(expected.OrderBy(c => c)); + } + [Fact] public void GivenDotnetAddPackWithPosition() { From 160fcfb57c7f0926a2bcdac1054f00298dad5f9f Mon Sep 17 00:00:00 2001 From: Advay Tandon Date: Thu, 6 Jun 2024 02:41:23 -0700 Subject: [PATCH 2/2] fixed --framework option's arity --- src/Cli/dotnet/commands/dotnet-nuget/NuGetCommandParser.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Cli/dotnet/commands/dotnet-nuget/NuGetCommandParser.cs b/src/Cli/dotnet/commands/dotnet-nuget/NuGetCommandParser.cs index 9d17a593aaa2..c7ab81a9400e 100644 --- a/src/Cli/dotnet/commands/dotnet-nuget/NuGetCommandParser.cs +++ b/src/Cli/dotnet/commands/dotnet-nuget/NuGetCommandParser.cs @@ -222,7 +222,7 @@ private static CliCommand GetWhyCommand() whyCommand.Arguments.Add(new CliArgument("PROJECT|SOLUTION") { Arity = ArgumentArity.ExactlyOne }); whyCommand.Arguments.Add(new CliArgument("PACKAGE") { Arity = ArgumentArity.ExactlyOne }); - whyCommand.Options.Add(new CliOption("--framework", "-f") { Arity = ArgumentArity.OneOrMore }); + whyCommand.Options.Add(new CliOption("--framework", "-f") { Arity = ArgumentArity.ZeroOrMore }); whyCommand.SetAction(NuGetCommand.Run);