Skip to content

Commit c933430

Browse files
[release/8.0.4xx] Add tab completion for 'dotnet nuget why' command (#41448)
Co-authored-by: Advay Tandon <[email protected]>
1 parent c60bff3 commit c933430

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

src/Cli/dotnet/commands/dotnet-nuget/NuGetCommandParser.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ private static CliCommand ConstructCommand()
3535
command.Subcommands.Add(GetVerifyCommand());
3636
command.Subcommands.Add(GetTrustCommand());
3737
command.Subcommands.Add(GetSignCommand());
38+
command.Subcommands.Add(GetWhyCommand());
3839

3940
command.SetAction(NuGetCommand.Run);
4041

@@ -213,5 +214,19 @@ private static CliCommand GetSignCommand()
213214

214215
return signCommand;
215216
}
217+
218+
private static CliCommand GetWhyCommand()
219+
{
220+
CliCommand whyCommand = new("why");
221+
222+
whyCommand.Arguments.Add(new CliArgument<string>("PROJECT|SOLUTION") { Arity = ArgumentArity.ExactlyOne });
223+
whyCommand.Arguments.Add(new CliArgument<string>("PACKAGE") { Arity = ArgumentArity.ExactlyOne });
224+
225+
whyCommand.Options.Add(new CliOption<string>("--framework", "-f") { Arity = ArgumentArity.ZeroOrMore });
226+
227+
whyCommand.SetAction(NuGetCommand.Run);
228+
229+
return whyCommand;
230+
}
216231
}
217232
}

src/Tests/dotnet-nuget.UnitTests/GivenANuGetCommand.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ public GivenANuGetCommand(ITestOutputHelper log) : base(log)
7575
"--interactive",
7676
"--verbosity", "detailed",
7777
"--format", "json"}, 0)]
78+
[InlineData(new[] { "why" }, 0)]
79+
[InlineData(new[] { "why", "C:\\path", "Fake.Package" }, 0)]
80+
[InlineData(new[] { "why", "C:\\path", "Fake.Package", "--framework", "net472", "-f", "netcoreapp5.0" }, 0)]
7881

7982
public void ItPassesCommandIfSupported(string[] inputArgs, int result)
8083
{

src/Tests/dotnet.Tests/CommandTests/CompleteCommandTests.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ public void GivenNuGetCommandItDisplaysCompletions()
118118
"push",
119119
"verify",
120120
"trust",
121-
"sign"
121+
"sign",
122+
"why"
122123
};
123124

124125
var reporter = new BufferedReporter();
@@ -286,6 +287,24 @@ public void GivenNuGetSignCommandItDisplaysCompletions()
286287
reporter.Lines.OrderBy(c => c).Should().Equal(expected.OrderBy(c => c));
287288
}
288289

290+
[Fact]
291+
public void GivenNuGetWhyCommandItDisplaysCompletions()
292+
{
293+
var expected = new[] {
294+
"--framework",
295+
"--help",
296+
"-?",
297+
"-f",
298+
"-h",
299+
"/?",
300+
"/h"
301+
};
302+
303+
var reporter = new BufferedReporter();
304+
CompleteCommand.RunWithReporter(new[] { "dotnet nuget why " }, reporter).Should().Be(0);
305+
reporter.Lines.OrderBy(c => c).Should().Equal(expected.OrderBy(c => c));
306+
}
307+
289308
[Fact]
290309
public void GivenDotnetAddPackWithPosition()
291310
{

0 commit comments

Comments
 (0)