Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Interactive without setting verbosity explicitly in dotnet tool restore Fixes #22987 #45312

Merged
merged 3 commits into from
Dec 20, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,7 @@ bool TryGetPackageMetadata(
try
{
SourceRepository repository = GetSourceRepository(source);
DefaultCredentialServiceUtility.SetupDefaultCredentialService(new NuGetConsoleLogger(), !_restoreActionConfig.Interactive);
PackageMetadataResource resource = await repository
.GetResourceAsync<PackageMetadataResource>(cancellationToken).ConfigureAwait(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.CommandLine;
using Microsoft.DotNet.Cli;
using Microsoft.DotNet.Cli.NuGetPackageDownloader;
using Microsoft.DotNet.Cli.ToolPackage;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.ToolManifest;
Expand All @@ -24,6 +25,7 @@ internal class ToolRestoreCommand : CommandBase
private readonly string[] _sources;
private readonly IToolPackageDownloader _toolPackageDownloader;
private readonly VerbosityOptions _verbosity;
private readonly RestoreActionConfig _restoreActionConfig;

public ToolRestoreCommand(
ParseResult result,
Expand Down Expand Up @@ -61,6 +63,15 @@ public ToolRestoreCommand(
_configFilePath = result.GetValue(ToolRestoreCommandParser.ConfigOption);
_sources = result.GetValue(ToolRestoreCommandParser.AddSourceOption);
_verbosity = result.GetValue(ToolRestoreCommandParser.VerbosityOption);
if (!result.HasOption(ToolRestoreCommandParser.VerbosityOption) && result.GetValue(ToolCommandRestorePassThroughOptions.InteractiveRestoreOption))
{
_verbosity = VerbosityOptions.minimal;
}

_restoreActionConfig = new RestoreActionConfig(DisableParallel: result.GetValue(ToolCommandRestorePassThroughOptions.DisableParallelOption),
NoCache: result.GetValue(ToolCommandRestorePassThroughOptions.NoCacheOption) || result.GetValue(ToolCommandRestorePassThroughOptions.NoHttpCacheOption),
IgnoreFailedSources: result.GetValue(ToolCommandRestorePassThroughOptions.IgnoreFailedSourcesOption),
Interactive: result.GetValue(ToolCommandRestorePassThroughOptions.InteractiveRestoreOption));
Comment on lines +66 to +74
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great! I have two broad comments:

  • I feel like I've seen this 'verbosity needs to be downstream of some other configuration' problem in a few different places in the codebase - is it something that you think we could detect and extract to prevent playing whack-a-mole?
  • the set of parameters to the RestoreActionConfig seem very 'regular' (in the sense of common/not-changing) - is there a way we could enforce that
    • commands that use RestoreActionConfig have the required options applied to them and
    • something in the way those commands are processed/executed automatically configures a RestoreActionConfig? Again focusing on 'How can we be consistent by design' here instead of playing whack-a-mole. Maybe a middleware or extension method on ParseResult or something?

}

public override int Execute()
Expand Down Expand Up @@ -130,7 +141,11 @@ private ToolRestoreResult InstallPackages(
nugetConfig: configFile,
additionalFeeds: _sources,
rootConfigDirectory: package.FirstEffectDirectory),
package.PackageId, verbosity: _verbosity, ToVersionRangeWithOnlyOneVersion(package.Version), targetFramework
package.PackageId,
verbosity: _verbosity,
ToVersionRangeWithOnlyOneVersion(package.Version),
targetFramework,
restoreActionConfig: _restoreActionConfig
);

if (!ManifestCommandMatchesActualInPackage(package.CommandNames, [toolPackage.Command]))
Expand Down
Loading