From d7b9504c9fd5e4f261cc91a62a449daace623d69 Mon Sep 17 00:00:00 2001 From: William Li Date: Tue, 14 Aug 2018 14:45:38 -0700 Subject: [PATCH] Select forward arguments to restore (#9830) --- src/dotnet/ToolPackage/ToolPackageFactory.cs | 6 ++-- .../ToolCommandRestorePassThroughOptions.cs | 36 +++++++++++++++++++ .../dotnet-tool/install/ProjectRestorer.cs | 11 +++++- .../dotnet-tool/install/ToolInstallCommand.cs | 9 +++-- .../install/ToolInstallCommandParser.cs | 5 ++- .../dotnet-tool/update/ToolUpdateCommand.cs | 3 +- .../update/ToolUpdateCommandParser.cs | 6 +++- .../CommandTests/ToolInstallCommandTests.cs | 13 +++---- .../CommandTests/ToolUninstallCommandTests.cs | 2 +- .../CommandTests/ToolUpdateCommandTests.cs | 8 ++--- .../ParserTests/InstallToolParserTests.cs | 30 ++++++++++++++++ .../ParserTests/UpdateToolParserTests.cs | 30 ++++++++++++++++ 12 files changed, 140 insertions(+), 19 deletions(-) create mode 100644 src/dotnet/commands/dotnet-tool/ToolCommandRestorePassThroughOptions.cs diff --git a/src/dotnet/ToolPackage/ToolPackageFactory.cs b/src/dotnet/ToolPackage/ToolPackageFactory.cs index 51f342fb9..3347cb6e9 100644 --- a/src/dotnet/ToolPackage/ToolPackageFactory.cs +++ b/src/dotnet/ToolPackage/ToolPackageFactory.cs @@ -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 additionalRestoreArguments = null) { IToolPackageStore toolPackageStore = CreateToolPackageStore(nonGlobalLocation); var toolPackageInstaller = new ToolPackageInstaller( toolPackageStore, - new ProjectRestorer()); + new ProjectRestorer(additionalRestoreArguments: additionalRestoreArguments)); return (toolPackageStore, toolPackageInstaller); } diff --git a/src/dotnet/commands/dotnet-tool/ToolCommandRestorePassThroughOptions.cs b/src/dotnet/commands/dotnet-tool/ToolCommandRestorePassThroughOptions.cs new file mode 100644 index 000000000..511f8b867 --- /dev/null +++ b/src/dotnet/commands/dotnet-tool/ToolCommandRestorePassThroughOptions.cs @@ -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")); + } + } +} diff --git a/src/dotnet/commands/dotnet-tool/install/ProjectRestorer.cs b/src/dotnet/commands/dotnet-tool/install/ProjectRestorer.cs index 1e2dfd8d3..088e7e505 100644 --- a/src/dotnet/commands/dotnet-tool/install/ProjectRestorer.cs +++ b/src/dotnet/commands/dotnet-tool/install/ProjectRestorer.cs @@ -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 _additionalRestoreArguments; - public ProjectRestorer(IReporter reporter = null) + public ProjectRestorer(IReporter reporter = null, + IEnumerable 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); diff --git a/src/dotnet/commands/dotnet-tool/install/ToolInstallCommand.cs b/src/dotnet/commands/dotnet-tool/install/ToolInstallCommand.cs index 49eb3d3f8..7fd8eb22c 100644 --- a/src/dotnet/commands/dotnet-tool/install/ToolInstallCommand.cs +++ b/src/dotnet/commands/dotnet-tool/install/ToolInstallCommand.cs @@ -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 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 _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 diff --git a/src/dotnet/commands/dotnet-tool/install/ToolInstallCommandParser.cs b/src/dotnet/commands/dotnet-tool/install/ToolInstallCommandParser.cs index 8d2b5f139..7b5bcffb5 100644 --- a/src/dotnet/commands/dotnet-tool/install/ToolInstallCommandParser.cs +++ b/src/dotnet/commands/dotnet-tool/install/ToolInstallCommandParser.cs @@ -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()); } diff --git a/src/dotnet/commands/dotnet-tool/update/ToolUpdateCommand.cs b/src/dotnet/commands/dotnet-tool/update/ToolUpdateCommand.cs index 318b5b267..ce8ea85dd 100644 --- a/src/dotnet/commands/dotnet-tool/update/ToolUpdateCommand.cs +++ b/src/dotnet/commands/dotnet-tool/update/ToolUpdateCommand.cs @@ -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 additionalRestoreArguments = null); internal class ToolUpdateCommand : CommandBase { diff --git a/src/dotnet/commands/dotnet-tool/update/ToolUpdateCommandParser.cs b/src/dotnet/commands/dotnet-tool/update/ToolUpdateCommandParser.cs index 6e866344d..5639c4b44 100644 --- a/src/dotnet/commands/dotnet-tool/update/ToolUpdateCommandParser.cs +++ b/src/dotnet/commands/dotnet-tool/update/ToolUpdateCommandParser.cs @@ -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()); } diff --git a/test/dotnet.Tests/CommandTests/ToolInstallCommandTests.cs b/test/dotnet.Tests/CommandTests/ToolInstallCommandTests.cs index c111e6104..981d77b84 100644 --- a/test/dotnet.Tests/CommandTests/ToolInstallCommandTests.cs +++ b/test/dotnet.Tests/CommandTests/ToolInstallCommandTests.cs @@ -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, diff --git a/test/dotnet.Tests/CommandTests/ToolUninstallCommandTests.cs b/test/dotnet.Tests/CommandTests/ToolUninstallCommandTests.cs index 516c2e26a..a968ceef7 100644 --- a/test/dotnet.Tests/CommandTests/ToolUninstallCommandTests.cs +++ b/test/dotnet.Tests/CommandTests/ToolUninstallCommandTests.cs @@ -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, diff --git a/test/dotnet.Tests/CommandTests/ToolUpdateCommandTests.cs b/test/dotnet.Tests/CommandTests/ToolUpdateCommandTests.cs index 17b969f8c..463034682 100644 --- a/test/dotnet.Tests/CommandTests/ToolUpdateCommandTests.cs +++ b/test/dotnet.Tests/CommandTests/ToolUpdateCommandTests.cs @@ -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( diff --git a/test/dotnet.Tests/ParserTests/InstallToolParserTests.cs b/test/dotnet.Tests/ParserTests/InstallToolParserTests.cs index b8042025a..6772fb6a8 100644 --- a/test/dotnet.Tests/ParserTests/InstallToolParserTests.cs +++ b/test/dotnet.Tests/ParserTests/InstallToolParserTests.cs @@ -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"); + } } } diff --git a/test/dotnet.Tests/ParserTests/UpdateToolParserTests.cs b/test/dotnet.Tests/ParserTests/UpdateToolParserTests.cs index 48284ee41..200123a0f 100644 --- a/test/dotnet.Tests/ParserTests/UpdateToolParserTests.cs +++ b/test/dotnet.Tests/ParserTests/UpdateToolParserTests.cs @@ -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"); + } } }