Select forward arguments to restore (#9830)

This commit is contained in:
William Li 2018-08-14 14:45:38 -07:00 committed by GitHub
parent 8ca823bfd6
commit d7b9504c9f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 140 additions and 19 deletions

View file

@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Collections.Generic;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.Configurer;
using Microsoft.DotNet.Tools.Tool.Install;
@ -11,12 +12,13 @@ namespace Microsoft.DotNet.ToolPackage
internal static class ToolPackageFactory
{
public static (IToolPackageStore, IToolPackageInstaller) CreateToolPackageStoreAndInstaller(
DirectoryPath? nonGlobalLocation = null)
DirectoryPath? nonGlobalLocation = null,
IEnumerable<string> additionalRestoreArguments = null)
{
IToolPackageStore toolPackageStore = CreateToolPackageStore(nonGlobalLocation);
var toolPackageInstaller = new ToolPackageInstaller(
toolPackageStore,
new ProjectRestorer());
new ProjectRestorer(additionalRestoreArguments: additionalRestoreArguments));
return (toolPackageStore, toolPackageInstaller);
}

View file

@ -0,0 +1,36 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using Microsoft.DotNet.Cli.CommandLine;
using LocalizableStrings = Microsoft.DotNet.Tools.Restore.LocalizableStrings;
namespace Microsoft.DotNet.Cli
{
internal static class ToolCommandRestorePassThroughOptions
{
public static Option DisableParallelOption()
{
return Create.Option(
"--disable-parallel",
LocalizableStrings.CmdDisableParallelOptionDescription,
Accept.NoArguments().ForwardAs("--disable-parallel"));
}
public static Option NoCacheOption()
{
return Create.Option(
"--no-cache",
LocalizableStrings.CmdNoCacheOptionDescription,
Accept.NoArguments().ForwardAs("--no-cache"));
}
public static Option IgnoreFailedSourcesOption()
{
return Create.Option(
"--ignore-failed-sources",
LocalizableStrings.CmdIgnoreFailedSourcesOptionDescription,
Accept.NoArguments().ForwardAs("--ignore-failed-sources"));
}
}
}

View file

@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.DotNet.Cli;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.Tools;
@ -18,9 +19,12 @@ namespace Microsoft.DotNet.Tools.Tool.Install
private readonly IReporter _reporter;
private readonly IReporter _errorReporter;
private readonly bool _forceOutputRedirection;
private readonly IEnumerable<string> _additionalRestoreArguments;
public ProjectRestorer(IReporter reporter = null)
public ProjectRestorer(IReporter reporter = null,
IEnumerable<string> additionalRestoreArguments = null)
{
_additionalRestoreArguments = additionalRestoreArguments;
_reporter = reporter ?? Reporter.Output;
_errorReporter = reporter ?? Reporter.Error;
_forceOutputRedirection = reporter != null;
@ -47,6 +51,11 @@ namespace Microsoft.DotNet.Tools.Tool.Install
argsToPassToRestore.Add($"-verbosity:{verbosity ?? "quiet"}");
if (_additionalRestoreArguments != null)
{
argsToPassToRestore.AddRange(_additionalRestoreArguments);
}
var command = new DotNetCommandFactory(alwaysRunOutOfProc: true)
.Create("restore", argsToPassToRestore);

View file

@ -18,7 +18,10 @@ using NuGet.Versioning;
namespace Microsoft.DotNet.Tools.Tool.Install
{
internal delegate IShellShimRepository CreateShellShimRepository(DirectoryPath? nonGlobalLocation = null);
internal delegate (IToolPackageStore, IToolPackageInstaller) CreateToolPackageStoreAndInstaller(DirectoryPath? nonGlobalLocation = null);
internal delegate (IToolPackageStore, IToolPackageInstaller) CreateToolPackageStoreAndInstaller(
DirectoryPath? nonGlobalLocation = null,
IEnumerable<string> forwardRestoreArguments = null);
internal class ToolInstallCommand : CommandBase
{
@ -36,6 +39,7 @@ namespace Microsoft.DotNet.Tools.Tool.Install
private readonly bool _global;
private readonly string _verbosity;
private readonly string _toolPath;
private IEnumerable<string> _forwardRestoreArguments;
public ToolInstallCommand(
AppliedOption appliedCommand,
@ -61,6 +65,7 @@ namespace Microsoft.DotNet.Tools.Tool.Install
_toolPath = appliedCommand.SingleArgumentOrDefault("tool-path");
_createToolPackageStoreAndInstaller = createToolPackageStoreAndInstaller ?? ToolPackageFactory.CreateToolPackageStoreAndInstaller;
_forwardRestoreArguments = appliedCommand.OptionValuesToBeForwarded();
_environmentPathInstruction = environmentPathInstruction
?? EnvironmentPathFactory.CreateEnvironmentPathInstruction();
@ -107,7 +112,7 @@ namespace Microsoft.DotNet.Tools.Tool.Install
}
(IToolPackageStore toolPackageStore, IToolPackageInstaller toolPackageInstaller) =
_createToolPackageStoreAndInstaller(toolPath);
_createToolPackageStoreAndInstaller(toolPath, _forwardRestoreArguments);
IShellShimRepository shellShimRepository = _createShellShimRepository(toolPath);
// Prevent installation if any version of the package is installed

View file

@ -33,7 +33,7 @@ namespace Microsoft.DotNet.Cli
"--configfile",
LocalizableStrings.ConfigFileOptionDescription,
Accept.ExactlyOneArgument()
.With(name: LocalizableStrings.ConfigFileOptionName)),
.With(name: LocalizableStrings.ConfigFileOptionName)),
Create.Option(
"--add-source",
LocalizableStrings.AddSourceOptionDescription,
@ -44,6 +44,9 @@ namespace Microsoft.DotNet.Cli
LocalizableStrings.FrameworkOptionDescription,
Accept.ExactlyOneArgument()
.With(name: LocalizableStrings.FrameworkOptionName)),
ToolCommandRestorePassThroughOptions.DisableParallelOption(),
ToolCommandRestorePassThroughOptions.IgnoreFailedSourcesOption(),
ToolCommandRestorePassThroughOptions.NoCacheOption(),
CommonOptions.HelpOption(),
CommonOptions.VerbosityOption());
}

View file

@ -20,7 +20,8 @@ namespace Microsoft.DotNet.Tools.Tool.Update
internal delegate IShellShimRepository CreateShellShimRepository(DirectoryPath? nonGlobalLocation = null);
internal delegate (IToolPackageStore, IToolPackageInstaller) CreateToolPackageStoreAndInstaller(
DirectoryPath? nonGlobalLocation = null);
DirectoryPath? nonGlobalLocation = null,
IEnumerable<string> additionalRestoreArguments = null);
internal class ToolUpdateCommand : CommandBase
{

View file

@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Linq;
using Microsoft.DotNet.Cli.CommandLine;
using LocalizableStrings = Microsoft.DotNet.Tools.Tool.Update.LocalizableStrings;
@ -28,7 +29,7 @@ namespace Microsoft.DotNet.Cli
"--configfile",
LocalizableStrings.ConfigFileOptionDescription,
Accept.ExactlyOneArgument()
.With(name: LocalizableStrings.ConfigFileOptionName)),
.With(name: LocalizableStrings.ConfigFileOptionName)),
Create.Option(
"--add-source",
LocalizableStrings.AddSourceOptionDescription,
@ -39,6 +40,9 @@ namespace Microsoft.DotNet.Cli
LocalizableStrings.FrameworkOptionDescription,
Accept.ExactlyOneArgument()
.With(name: LocalizableStrings.FrameworkOptionName)),
ToolCommandRestorePassThroughOptions.DisableParallelOption(),
ToolCommandRestorePassThroughOptions.IgnoreFailedSourcesOption(),
ToolCommandRestorePassThroughOptions.NoCacheOption(),
CommonOptions.HelpOption(),
CommonOptions.VerbosityOption());
}

View file

@ -57,7 +57,8 @@ namespace Microsoft.DotNet.Tests.Commands
filePermissionSetter: new NoOpFilePermissionSetter());
_environmentPathInstructionMock =
new EnvironmentPathInstructionMock(_reporter, _pathToPlaceShim);
_createToolPackageStoreAndInstaller = (_) => (_toolPackageStore, CreateToolPackageInstaller());
_createToolPackageStoreAndInstaller =
(location, forwardArguments) => (_toolPackageStore, CreateToolPackageInstaller());
ParseResult result = Parser.Instance.Parse($"dotnet tool install -g {PackageId}");
_appliedCommand = result["dotnet"]["tool"]["install"];
@ -114,7 +115,7 @@ namespace Microsoft.DotNet.Tests.Commands
var installCommand = new ToolInstallCommand(appliedCommand,
parseResult,
(_) => (_toolPackageStore, toolToolPackageInstaller),
(location, forwardArguments) => (_toolPackageStore, toolToolPackageInstaller),
_createShellShimRepository,
_environmentPathInstructionMock,
_reporter);
@ -165,7 +166,7 @@ namespace Microsoft.DotNet.Tests.Commands
var installToolCommand = new ToolInstallCommand(
_appliedCommand,
_parseResult,
(_) => (_toolPackageStore, toolPackageInstaller),
(location, forwardArguments) => (_toolPackageStore, toolPackageInstaller),
_createShellShimRepository,
_environmentPathInstructionMock,
_reporter);
@ -188,7 +189,7 @@ namespace Microsoft.DotNet.Tests.Commands
var installCommand = new ToolInstallCommand(
_appliedCommand,
_parseResult,
(_) => (_toolPackageStore, toolPackageInstaller),
(location, forwardArguments) => (_toolPackageStore, toolPackageInstaller),
_createShellShimRepository,
_environmentPathInstructionMock,
_reporter);
@ -237,7 +238,7 @@ namespace Microsoft.DotNet.Tests.Commands
var installCommand = new ToolInstallCommand(
_appliedCommand,
_parseResult,
(_) => (_toolPackageStore, toolPackageInstaller),
(location, forwardArguments) => (_toolPackageStore, toolPackageInstaller),
_createShellShimRepository,
_environmentPathInstructionMock,
_reporter);
@ -486,7 +487,7 @@ namespace Microsoft.DotNet.Tests.Commands
var installCommand = new ToolInstallCommand(appliedCommand,
parseResult,
(_) => (_toolPackageStore, new ToolPackageInstallerMock(
(location, forwardArguments) => (_toolPackageStore, new ToolPackageInstallerMock(
fileSystem: _fileSystem,
store: _toolPackageStore,
packagedShimsMap: packagedShimsMap,

View file

@ -206,7 +206,7 @@ namespace Microsoft.DotNet.Tests.Commands
return new ToolInstallCommand(
result["dotnet"]["tool"]["install"],
result,
(_) => (store, packageInstallerMock),
(location, forwardArguments) => (store, packageInstallerMock),
(_) => new ShellShimRepository(
new DirectoryPath(_shimsDirectory),
fileSystem: _fileSystem,

View file

@ -134,7 +134,7 @@ namespace Microsoft.DotNet.Tests.Commands
var command = new ToolUpdateCommand(
result["dotnet"]["tool"]["update"],
result,
_ => (_store,
(location, forwardArguments) => (_store,
new ToolPackageInstallerMock(
_fileSystem,
_store,
@ -163,7 +163,7 @@ namespace Microsoft.DotNet.Tests.Commands
var command = new ToolUpdateCommand(
result["dotnet"]["tool"]["update"],
result,
_ => (_store,
(location, forwardArguments) => (_store,
new ToolPackageInstallerMock(
_fileSystem,
_store,
@ -213,7 +213,7 @@ namespace Microsoft.DotNet.Tests.Commands
return new ToolInstallCommand(
result["dotnet"]["tool"]["install"],
result,
(_) => (_store, new ToolPackageInstallerMock(
(location, forwardArguments) => (_store, new ToolPackageInstallerMock(
_fileSystem,
_store,
new ProjectRestorerMock(
@ -233,7 +233,7 @@ namespace Microsoft.DotNet.Tests.Commands
return new ToolUpdateCommand(
result["dotnet"]["tool"]["update"],
result,
(_) => (_store, new ToolPackageInstallerMock(
(location, forwardArguments) => (_store, new ToolPackageInstallerMock(
_fileSystem,
_store,
new ProjectRestorerMock(

View file

@ -108,5 +108,35 @@ namespace Microsoft.DotNet.Tests.ParserTests
var appliedOptions = result["dotnet"]["tool"]["install"];
appliedOptions.SingleArgumentOrDefault("tool-path").Should().Be(@"C:\Tools");
}
[Fact]
public void InstallToolParserCanParseNoCacheOption()
{
var result =
Parser.Instance.Parse(@"dotnet tool install -g console.test.app --no-cache");
var appliedOptions = result["dotnet"]["tool"]["install"];
appliedOptions.OptionValuesToBeForwarded().Should().ContainSingle("--no-cache");
}
[Fact]
public void InstallToolParserCanParseIgnoreFailedSourcesOption()
{
var result =
Parser.Instance.Parse(@"dotnet tool install -g console.test.app --ignore-failed-sources");
var appliedOptions = result["dotnet"]["tool"]["install"];
appliedOptions.OptionValuesToBeForwarded().Should().ContainSingle("--ignore-failed-sources");
}
[Fact]
public void InstallToolParserCanParseDisableParallelOption()
{
var result =
Parser.Instance.Parse(@"dotnet tool install -g console.test.app --disable-parallel");
var appliedOptions = result["dotnet"]["tool"]["install"];
appliedOptions.OptionValuesToBeForwarded().Should().ContainSingle("--disable-parallel");
}
}
}

View file

@ -107,5 +107,35 @@ namespace Microsoft.DotNet.Tests.ParserTests
var appliedOptions = result["dotnet"]["tool"]["update"];
appliedOptions.SingleArgumentOrDefault("tool-path").Should().Be(@"C:\TestAssetLocalNugetFeed");
}
[Fact]
public void UpdateToolParserCanParseNoCacheOption()
{
var result =
Parser.Instance.Parse(@"dotnet tool update -g console.test.app --no-cache");
var appliedOptions = result["dotnet"]["tool"]["update"];
appliedOptions.OptionValuesToBeForwarded().Should().ContainSingle("--no-cache");
}
[Fact]
public void UpdateToolParserCanParseIgnoreFailedSourcesOption()
{
var result =
Parser.Instance.Parse(@"dotnet tool update -g console.test.app --ignore-failed-sources");
var appliedOptions = result["dotnet"]["tool"]["update"];
appliedOptions.OptionValuesToBeForwarded().Should().ContainSingle("--ignore-failed-sources");
}
[Fact]
public void UpdateToolParserCanParseDisableParallelOption()
{
var result =
Parser.Instance.Parse(@"dotnet tool update -g console.test.app --disable-parallel");
var appliedOptions = result["dotnet"]["tool"]["update"];
appliedOptions.OptionValuesToBeForwarded().Should().ContainSingle("--disable-parallel");
}
}
}