Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add dotnet nuget why command
  • Loading branch information
advay26 authored and github-actions committed Jun 6, 2024
commit 1da075298035071b75554489aaa641b3be02376b
15 changes: 15 additions & 0 deletions src/Cli/dotnet/commands/dotnet-nuget/NuGetCommandParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -213,5 +214,19 @@ private static CliCommand GetSignCommand()

return signCommand;
}

private static CliCommand GetWhyCommand()
{
CliCommand whyCommand = new("why");

whyCommand.Arguments.Add(new CliArgument<string>("PROJECT|SOLUTION") { Arity = ArgumentArity.ExactlyOne });
whyCommand.Arguments.Add(new CliArgument<string>("PACKAGE") { Arity = ArgumentArity.ExactlyOne });

whyCommand.Options.Add(new CliOption<string>("--framework", "-f") { Arity = ArgumentArity.OneOrMore });

whyCommand.SetAction(NuGetCommand.Run);

return whyCommand;
}
}
}
3 changes: 3 additions & 0 deletions src/Tests/dotnet-nuget.UnitTests/GivenANuGetCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
21 changes: 20 additions & 1 deletion src/Tests/dotnet.Tests/CommandTests/CompleteCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ public void GivenNuGetCommandItDisplaysCompletions()
"push",
"verify",
"trust",
"sign"
"sign",
"why"
};

var reporter = new BufferedReporter();
Expand Down Expand Up @@ -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()
{
Expand Down