Skip to content

Commit

Permalink
Make CLI parser public for dotnet nuget why (#6118)
Browse files Browse the repository at this point in the history
  • Loading branch information
zivkan authored Oct 28, 2024
1 parent 104dc44 commit a97fb42
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace NuGet.CommandLine.XPlat.Commands.Why
{
internal static class WhyCommand
public static class WhyCommand
{
internal static void Register(CommandLineApplication app)
{
Expand All @@ -25,6 +25,16 @@ internal static void Register(CliCommand rootCommand, Func<ILoggerWithColor> get
Register(rootCommand, getLogger, WhyCommandRunner.ExecuteCommand);
}

/// <summary>
/// This is a temporary API until NuGet migrates all our commands to System.CommandLine, at which time I suspect we'll have a NuGetParser.GetNuGetCommand for all the `dotnet nuget *` commands.
/// For now, this allows the dotnet CLI to invoke why directly, instead of running NuGet.CommandLine.XPlat as a child process.
/// </summary>
/// <param name="rootCommand">The <c>dotnet nuget</c> command handler, to add <c>why</c> to.</param>
public static void GetWhyCommand(CliCommand rootCommand)
{
Register(rootCommand, CommandOutputLogger.Create, WhyCommandRunner.ExecuteCommand);
}

internal static void Register(CliCommand rootCommand, Func<ILoggerWithColor> getLogger, Func<WhyCommandArgs, int> action)
{
var whyCommand = new CliCommand("why", Strings.WhyCommand_Description);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NuGet.CommandLine.XPlat.Commands.Why.WhyCommand
static NuGet.CommandLine.XPlat.Commands.Why.WhyCommand.GetWhyCommand(System.CommandLine.CliCommand rootCommand) -> void
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ public CommandOutputLogger(LogLevel logLevel)
VerbosityLevel = logLevel;
}

/// <summary>
/// Create a CommandOutputLogger for commands invoked by the .NET CLI
/// </summary>
/// <returns></returns>
public static CommandOutputLogger Create()
{
var logger = new CommandOutputLogger(LogLevel.Information);
logger.HidePrefixForInfoAndMinimal = true;
return logger;
}

public override void LogDebug(string data)
{
LogInternal(LogLevel.Debug, data);
Expand Down

0 comments on commit a97fb42

Please sign in to comment.