Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
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 @@ -36,6 +36,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 @@ -216,5 +217,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.ZeroOrMore });

whyCommand.SetAction(NuGetCommand.Run);

return whyCommand;
}
}
}
3 changes: 3 additions & 0 deletions test/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 test/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