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
7 changes: 7 additions & 0 deletions src/Cli/dotnet/commands/dotnet-help/HelpCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using Microsoft.DotNet.Cli;
using Microsoft.DotNet.Cli.Utils;

using NuGetDocumentedCommand = NuGet.CommandLine.XPlat.Commands.DocumentedCommand;

namespace Microsoft.DotNet.Tools.Help
{
public class HelpCommand(string[] helpArgs)
Expand Down Expand Up @@ -106,6 +108,11 @@ private bool TryGetDocsLink(string[] command, out string docsLink)
docsLink = dc.DocsLink;
return true;
}
else if (parsedCommand?.CommandResult?.Command is NuGetDocumentedCommand ndc)
{
docsLink = ndc.HelpUrl;
return true;
}
docsLink = null;
return false;
}
Expand Down
16 changes: 1 addition & 15 deletions src/Cli/dotnet/commands/dotnet-nuget/NuGetCommandParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ private static CliCommand ConstructCommand()
command.Subcommands.Add(GetVerifyCommand());
command.Subcommands.Add(GetTrustCommand());
command.Subcommands.Add(GetSignCommand());
command.Subcommands.Add(GetWhyCommand());
NuGet.CommandLine.XPlat.Commands.Why.WhyCommand.GetWhyCommand(command);

command.SetAction(NuGetCommand.Run);

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

return signCommand;
}

private static CliCommand GetWhyCommand()
{
DocumentedCommand whyCommand = new("why", "https://learn.microsoft.com/dotnet/core/tools/dotnet-nuget-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 ForwardedOption<IEnumerable<string>>("--framework", "-f") { Arity = ArgumentArity.ZeroOrMore }
.ForwardAsManyArgumentsEachPrefixedByOption("--framework")
.AllowSingleArgPerToken());

whyCommand.SetAction(NuGetCommand.Run);
return whyCommand;
}
}
}
1 change: 1 addition & 0 deletions src/Cli/dotnet/dotnet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" />
<PackageReference Include="NuGet.CommandLine.XPlat" />
<PackageReference Include="Microsoft.ApplicationInsights" />
<PackageReference Include="Microsoft.Build" />
<PackageReference Include="Microsoft.NET.HostModel" />
Expand Down
27 changes: 24 additions & 3 deletions test/dotnet-nuget.UnitTests/GivenANuGetCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,6 @@ 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 Expand Up @@ -110,5 +107,29 @@ public void ItAcceptsPrefixedOption()
.And
.HaveStdErrContaining("Required argument missing for option: '-ss'.");
}

[Fact]
public void ItHasAWhySubcommand()
{
var testAssetName = "NewtonSoftDependentProject";
var testAsset = _testAssetsManager
.CopyTestAsset(testAssetName)
.WithSource();
var projectDirectory = testAsset.Path;

new RestoreCommand(testAsset)
.Execute()
.Should()
.Pass()
.And.NotHaveStdErr();

new DotnetCommand(Log)
.WithWorkingDirectory(projectDirectory)
.Execute("nuget", "why", "newtonsoft.json")
.Should()
.Pass()
.And.NotHaveStdErr()
.And.HaveStdOutContaining("has the following dependency");
}
}
}
Loading