From d3244e8ef0670dc43dc33d327c07782dded21176 Mon Sep 17 00:00:00 2001 From: Peter Huene Date: Fri, 16 Mar 2018 19:47:34 -0700 Subject: [PATCH 1/2] Ensure tool package store root is a full path. This commit fixes the tool package store such that it stores a full path instead of, potentially, a relative path. This prevents a relative path from inadvertently being passed to NuGet during the restore and causing it to restore relative to the temp project directory. Fixes #8829. --- src/dotnet/ToolPackage/ToolPackageStore.cs | 2 +- .../ToolPackageInstallerTests.cs | 4 +++- .../ToolPackageStoreMock.cs | 2 +- test/dotnet.Tests/CommandTests/UninstallToolCommandTests.cs | 6 ++++-- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/dotnet/ToolPackage/ToolPackageStore.cs b/src/dotnet/ToolPackage/ToolPackageStore.cs index f424b6062..24ec84289 100644 --- a/src/dotnet/ToolPackage/ToolPackageStore.cs +++ b/src/dotnet/ToolPackage/ToolPackageStore.cs @@ -14,7 +14,7 @@ namespace Microsoft.DotNet.ToolPackage public ToolPackageStore(DirectoryPath root) { - Root = root; + Root = new DirectoryPath(Path.GetFullPath(root.Value)); } public DirectoryPath Root { get; private set; } diff --git a/test/Microsoft.DotNet.ToolPackage.Tests/ToolPackageInstallerTests.cs b/test/Microsoft.DotNet.ToolPackage.Tests/ToolPackageInstallerTests.cs index b487c7dfb..d03af3951 100644 --- a/test/Microsoft.DotNet.ToolPackage.Tests/ToolPackageInstallerTests.cs +++ b/test/Microsoft.DotNet.ToolPackage.Tests/ToolPackageInstallerTests.cs @@ -637,7 +637,7 @@ namespace Microsoft.DotNet.ToolPackage.Tests FilePath? tempProject = null, DirectoryPath? offlineFeed = null) { - var root = new DirectoryPath(Path.Combine(Path.GetFullPath(TempRoot.Root), Path.GetRandomFileName())); + var root = new DirectoryPath(Path.Combine(TempRoot.Root, Path.GetRandomFileName())); var reporter = new BufferedReporter(); IFileSystem fileSystem; @@ -666,6 +666,8 @@ namespace Microsoft.DotNet.ToolPackage.Tests offlineFeed: offlineFeed ?? new DirectoryPath("does not exist")); } + store.Root.Value.Should().Be(Path.GetFullPath(root.Value)); + return (store, installer, reporter, fileSystem); } diff --git a/test/Microsoft.DotNet.Tools.Tests.ComponentMocks/ToolPackageStoreMock.cs b/test/Microsoft.DotNet.Tools.Tests.ComponentMocks/ToolPackageStoreMock.cs index e8219560c..43203a635 100644 --- a/test/Microsoft.DotNet.Tools.Tests.ComponentMocks/ToolPackageStoreMock.cs +++ b/test/Microsoft.DotNet.Tools.Tests.ComponentMocks/ToolPackageStoreMock.cs @@ -22,7 +22,7 @@ namespace Microsoft.DotNet.Tools.Tests.ComponentMocks IFileSystem fileSystem, Action uninstallCallback = null) { - Root = root; + Root = new DirectoryPath(Path.GetFullPath(root.Value)); _fileSystem = fileSystem ?? throw new ArgumentNullException(nameof(fileSystem)); _uninstallCallback = uninstallCallback; } diff --git a/test/dotnet.Tests/CommandTests/UninstallToolCommandTests.cs b/test/dotnet.Tests/CommandTests/UninstallToolCommandTests.cs index 813a70ec4..4707f8e1c 100644 --- a/test/dotnet.Tests/CommandTests/UninstallToolCommandTests.cs +++ b/test/dotnet.Tests/CommandTests/UninstallToolCommandTests.cs @@ -73,7 +73,8 @@ namespace Microsoft.DotNet.Tests.Commands PackageId, PackageVersion)); - var packageDirectory = new DirectoryPath(ToolsDirectory).WithSubDirectories(PackageId, PackageVersion); + var packageDirectory = new DirectoryPath(Path.GetFullPath(ToolsDirectory)) + .WithSubDirectories(PackageId, PackageVersion); var shimPath = Path.Combine( ShimsDirectory, ProjectRestorerMock.FakeCommandName + @@ -114,7 +115,8 @@ namespace Microsoft.DotNet.Tests.Commands PackageId, PackageVersion)); - var packageDirectory = new DirectoryPath(ToolsDirectory).WithSubDirectories(PackageId, PackageVersion); + var packageDirectory = new DirectoryPath(Path.GetFullPath(ToolsDirectory)) + .WithSubDirectories(PackageId, PackageVersion); var shimPath = Path.Combine( ShimsDirectory, ProjectRestorerMock.FakeCommandName + From 95c0359d26ef4045a05fbd12d17d161b2f5e358f Mon Sep 17 00:00:00 2001 From: Peter Huene Date: Fri, 16 Mar 2018 14:56:24 -0700 Subject: [PATCH 2/2] Implement the --tool-path option for the list tool command. This commit implements the missing `--tool-path` option for the list tool command. This enables the command to list locally installed tools. Fixes #8803. --- .../dotnet-list-tool/ListToolCommand.cs | 33 ++++++++---- .../dotnet-list-tool/ListToolCommandParser.cs | 4 ++ .../dotnet-list-tool/LocalizableStrings.resx | 10 +++- .../xlf/LocalizableStrings.cs.xlf | 20 +++++-- .../xlf/LocalizableStrings.de.xlf | 20 +++++-- .../xlf/LocalizableStrings.es.xlf | 20 +++++-- .../xlf/LocalizableStrings.fr.xlf | 20 +++++-- .../xlf/LocalizableStrings.it.xlf | 20 +++++-- .../xlf/LocalizableStrings.ja.xlf | 20 +++++-- .../xlf/LocalizableStrings.ko.xlf | 20 +++++-- .../xlf/LocalizableStrings.pl.xlf | 20 +++++-- .../xlf/LocalizableStrings.pt-BR.xlf | 20 +++++-- .../xlf/LocalizableStrings.ru.xlf | 20 +++++-- .../xlf/LocalizableStrings.tr.xlf | 20 +++++-- .../xlf/LocalizableStrings.zh-Hans.xlf | 20 +++++-- .../xlf/LocalizableStrings.zh-Hant.xlf | 20 +++++-- .../tool/UninstallToolCommand.cs | 8 +-- .../CommandTests/ListToolCommandTests.cs | 54 +++++++++++++++++-- .../ParserTests/InstallToolParserTests.cs | 4 +- .../ParserTests/ListToolParserTests.cs | 42 +++++++++++++++ ...erTests.cs => UninstallToolParserTests.cs} | 10 ++-- 21 files changed, 334 insertions(+), 91 deletions(-) create mode 100644 test/dotnet.Tests/ParserTests/ListToolParserTests.cs rename test/dotnet.Tests/ParserTests/{UninstallInstallToolParserTests.cs => UninstallToolParserTests.cs} (84%) diff --git a/src/dotnet/commands/dotnet-list/dotnet-list-tool/ListToolCommand.cs b/src/dotnet/commands/dotnet-list/dotnet-list-tool/ListToolCommand.cs index 2c3608d3c..9d00b45eb 100644 --- a/src/dotnet/commands/dotnet-list/dotnet-list-tool/ListToolCommand.cs +++ b/src/dotnet/commands/dotnet-list/dotnet-list-tool/ListToolCommand.cs @@ -13,33 +13,48 @@ using Microsoft.Extensions.EnvironmentAbstractions; namespace Microsoft.DotNet.Tools.List.Tool { + internal delegate IToolPackageStore CreateToolPackageStore(DirectoryPath? nonGlobalLocation = null); + internal class ListToolCommand : CommandBase { public const string CommandDelimiter = ", "; private readonly AppliedOption _options; - private readonly IToolPackageStore _toolPackageStore; private readonly IReporter _reporter; private readonly IReporter _errorReporter; + private CreateToolPackageStore _createToolPackageStore; public ListToolCommand( AppliedOption options, ParseResult result, - IToolPackageStore toolPackageStore = null, + CreateToolPackageStore createToolPackageStore = null, IReporter reporter = null) : base(result) { _options = options ?? throw new ArgumentNullException(nameof(options)); - _toolPackageStore = toolPackageStore ?? new ToolPackageStore( - new DirectoryPath(new CliFolderPathCalculator().ToolsPackagePath)); _reporter = reporter ?? Reporter.Output; _errorReporter = reporter ?? Reporter.Error; + _createToolPackageStore = createToolPackageStore ?? ToolPackageFactory.CreateToolPackageStore; } public override int Execute() { - if (!_options.ValueOrDefault("global")) + var global = _options.ValueOrDefault("global"); + var toolPathOption = _options.ValueOrDefault("tool-path"); + + DirectoryPath? toolPath = null; + if (!string.IsNullOrWhiteSpace(toolPathOption)) { - throw new GracefulException(LocalizableStrings.ListToolCommandOnlySupportsGlobal); + toolPath = new DirectoryPath(toolPathOption); + } + + if (toolPath == null && !global) + { + throw new GracefulException(LocalizableStrings.NeedGlobalOrToolPath); + } + + if (toolPath != null && global) + { + throw new GracefulException(LocalizableStrings.GlobalAndToolPathConflict); } var table = new PrintableTable(); @@ -54,13 +69,13 @@ namespace Microsoft.DotNet.Tools.List.Tool LocalizableStrings.CommandsColumn, p => string.Join(CommandDelimiter, p.Commands.Select(c => c.Name))); - table.PrintRows(GetPackages(), l => _reporter.WriteLine(l)); + table.PrintRows(GetPackages(toolPath), l => _reporter.WriteLine(l)); return 0; } - private IEnumerable GetPackages() + private IEnumerable GetPackages(DirectoryPath? toolPath) { - return _toolPackageStore.EnumeratePackages() + return _createToolPackageStore(toolPath).EnumeratePackages() .Where(PackageHasCommands) .OrderBy(p => p.Id) .ToArray(); diff --git a/src/dotnet/commands/dotnet-list/dotnet-list-tool/ListToolCommandParser.cs b/src/dotnet/commands/dotnet-list/dotnet-list-tool/ListToolCommandParser.cs index c75e2e1ac..b8a5084aa 100644 --- a/src/dotnet/commands/dotnet-list/dotnet-list-tool/ListToolCommandParser.cs +++ b/src/dotnet/commands/dotnet-list/dotnet-list-tool/ListToolCommandParser.cs @@ -17,6 +17,10 @@ namespace Microsoft.DotNet.Cli "-g|--global", LocalizableStrings.GlobalOptionDescription, Accept.NoArguments()), + Create.Option( + "--tool-path", + LocalizableStrings.ToolPathDescription, + Accept.ExactlyOneArgument()), CommonOptions.HelpOption()); } } diff --git a/src/dotnet/commands/dotnet-list/dotnet-list-tool/LocalizableStrings.resx b/src/dotnet/commands/dotnet-list/dotnet-list-tool/LocalizableStrings.resx index b4d21c122..852ca839b 100644 --- a/src/dotnet/commands/dotnet-list/dotnet-list-tool/LocalizableStrings.resx +++ b/src/dotnet/commands/dotnet-list/dotnet-list-tool/LocalizableStrings.resx @@ -123,8 +123,14 @@ List user wide tools. - - The --global switch (-g) is currently required because only user wide tools are supported. + + Location where the tools are installed. + + + Please specify either the global option (--global) or the tool path option (--tool-path). + + + (--global) conflicts with the tool path option (--tool-path). Please specify only one of the options. Warning: tool package '{0}' is invalid: {1} diff --git a/src/dotnet/commands/dotnet-list/dotnet-list-tool/xlf/LocalizableStrings.cs.xlf b/src/dotnet/commands/dotnet-list/dotnet-list-tool/xlf/LocalizableStrings.cs.xlf index 649e0ecf4..947520d2c 100644 --- a/src/dotnet/commands/dotnet-list/dotnet-list-tool/xlf/LocalizableStrings.cs.xlf +++ b/src/dotnet/commands/dotnet-list/dotnet-list-tool/xlf/LocalizableStrings.cs.xlf @@ -12,11 +12,6 @@ List user wide tools. - - The --global switch (-g) is currently required because only user wide tools are supported. - The --global switch (-g) is currently required because only user wide tools are supported. - - Version Version @@ -37,6 +32,21 @@ Warning: tool package '{0}' is invalid: {1} + + Location where the tools are installed. + Location where the tools are installed. + + + + Please specify either the global option (--global) or the tool path option (--tool-path). + Please specify either the global option (--global) or the tool path option (--tool-path). + + + + (--global) conflicts with the tool path option (--tool-path). Please specify only one of the options. + (--global) conflicts with the tool path option (--tool-path). Please specify only one of the options. + + \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-list/dotnet-list-tool/xlf/LocalizableStrings.de.xlf b/src/dotnet/commands/dotnet-list/dotnet-list-tool/xlf/LocalizableStrings.de.xlf index ea32b1a2c..3ebb7fd97 100644 --- a/src/dotnet/commands/dotnet-list/dotnet-list-tool/xlf/LocalizableStrings.de.xlf +++ b/src/dotnet/commands/dotnet-list/dotnet-list-tool/xlf/LocalizableStrings.de.xlf @@ -12,11 +12,6 @@ List user wide tools. - - The --global switch (-g) is currently required because only user wide tools are supported. - The --global switch (-g) is currently required because only user wide tools are supported. - - Version Version @@ -37,6 +32,21 @@ Warning: tool package '{0}' is invalid: {1} + + Location where the tools are installed. + Location where the tools are installed. + + + + Please specify either the global option (--global) or the tool path option (--tool-path). + Please specify either the global option (--global) or the tool path option (--tool-path). + + + + (--global) conflicts with the tool path option (--tool-path). Please specify only one of the options. + (--global) conflicts with the tool path option (--tool-path). Please specify only one of the options. + + \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-list/dotnet-list-tool/xlf/LocalizableStrings.es.xlf b/src/dotnet/commands/dotnet-list/dotnet-list-tool/xlf/LocalizableStrings.es.xlf index 65116604b..debaab941 100644 --- a/src/dotnet/commands/dotnet-list/dotnet-list-tool/xlf/LocalizableStrings.es.xlf +++ b/src/dotnet/commands/dotnet-list/dotnet-list-tool/xlf/LocalizableStrings.es.xlf @@ -12,11 +12,6 @@ List user wide tools. - - The --global switch (-g) is currently required because only user wide tools are supported. - The --global switch (-g) is currently required because only user wide tools are supported. - - Version Version @@ -37,6 +32,21 @@ Warning: tool package '{0}' is invalid: {1} + + Location where the tools are installed. + Location where the tools are installed. + + + + Please specify either the global option (--global) or the tool path option (--tool-path). + Please specify either the global option (--global) or the tool path option (--tool-path). + + + + (--global) conflicts with the tool path option (--tool-path). Please specify only one of the options. + (--global) conflicts with the tool path option (--tool-path). Please specify only one of the options. + + \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-list/dotnet-list-tool/xlf/LocalizableStrings.fr.xlf b/src/dotnet/commands/dotnet-list/dotnet-list-tool/xlf/LocalizableStrings.fr.xlf index 0f383597d..ad6de0b05 100644 --- a/src/dotnet/commands/dotnet-list/dotnet-list-tool/xlf/LocalizableStrings.fr.xlf +++ b/src/dotnet/commands/dotnet-list/dotnet-list-tool/xlf/LocalizableStrings.fr.xlf @@ -12,11 +12,6 @@ List user wide tools. - - The --global switch (-g) is currently required because only user wide tools are supported. - The --global switch (-g) is currently required because only user wide tools are supported. - - Version Version @@ -37,6 +32,21 @@ Warning: tool package '{0}' is invalid: {1} + + Location where the tools are installed. + Location where the tools are installed. + + + + Please specify either the global option (--global) or the tool path option (--tool-path). + Please specify either the global option (--global) or the tool path option (--tool-path). + + + + (--global) conflicts with the tool path option (--tool-path). Please specify only one of the options. + (--global) conflicts with the tool path option (--tool-path). Please specify only one of the options. + + \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-list/dotnet-list-tool/xlf/LocalizableStrings.it.xlf b/src/dotnet/commands/dotnet-list/dotnet-list-tool/xlf/LocalizableStrings.it.xlf index 33a6f2083..4859f9ab7 100644 --- a/src/dotnet/commands/dotnet-list/dotnet-list-tool/xlf/LocalizableStrings.it.xlf +++ b/src/dotnet/commands/dotnet-list/dotnet-list-tool/xlf/LocalizableStrings.it.xlf @@ -12,11 +12,6 @@ List user wide tools. - - The --global switch (-g) is currently required because only user wide tools are supported. - The --global switch (-g) is currently required because only user wide tools are supported. - - Version Version @@ -37,6 +32,21 @@ Warning: tool package '{0}' is invalid: {1} + + Location where the tools are installed. + Location where the tools are installed. + + + + Please specify either the global option (--global) or the tool path option (--tool-path). + Please specify either the global option (--global) or the tool path option (--tool-path). + + + + (--global) conflicts with the tool path option (--tool-path). Please specify only one of the options. + (--global) conflicts with the tool path option (--tool-path). Please specify only one of the options. + + \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-list/dotnet-list-tool/xlf/LocalizableStrings.ja.xlf b/src/dotnet/commands/dotnet-list/dotnet-list-tool/xlf/LocalizableStrings.ja.xlf index c9e468b1a..4e9d50460 100644 --- a/src/dotnet/commands/dotnet-list/dotnet-list-tool/xlf/LocalizableStrings.ja.xlf +++ b/src/dotnet/commands/dotnet-list/dotnet-list-tool/xlf/LocalizableStrings.ja.xlf @@ -12,11 +12,6 @@ List user wide tools. - - The --global switch (-g) is currently required because only user wide tools are supported. - The --global switch (-g) is currently required because only user wide tools are supported. - - Version Version @@ -37,6 +32,21 @@ Warning: tool package '{0}' is invalid: {1} + + Location where the tools are installed. + Location where the tools are installed. + + + + Please specify either the global option (--global) or the tool path option (--tool-path). + Please specify either the global option (--global) or the tool path option (--tool-path). + + + + (--global) conflicts with the tool path option (--tool-path). Please specify only one of the options. + (--global) conflicts with the tool path option (--tool-path). Please specify only one of the options. + + \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-list/dotnet-list-tool/xlf/LocalizableStrings.ko.xlf b/src/dotnet/commands/dotnet-list/dotnet-list-tool/xlf/LocalizableStrings.ko.xlf index 7d5475c1f..75aa8d88d 100644 --- a/src/dotnet/commands/dotnet-list/dotnet-list-tool/xlf/LocalizableStrings.ko.xlf +++ b/src/dotnet/commands/dotnet-list/dotnet-list-tool/xlf/LocalizableStrings.ko.xlf @@ -12,11 +12,6 @@ List user wide tools. - - The --global switch (-g) is currently required because only user wide tools are supported. - The --global switch (-g) is currently required because only user wide tools are supported. - - Version Version @@ -37,6 +32,21 @@ Warning: tool package '{0}' is invalid: {1} + + Location where the tools are installed. + Location where the tools are installed. + + + + Please specify either the global option (--global) or the tool path option (--tool-path). + Please specify either the global option (--global) or the tool path option (--tool-path). + + + + (--global) conflicts with the tool path option (--tool-path). Please specify only one of the options. + (--global) conflicts with the tool path option (--tool-path). Please specify only one of the options. + + \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-list/dotnet-list-tool/xlf/LocalizableStrings.pl.xlf b/src/dotnet/commands/dotnet-list/dotnet-list-tool/xlf/LocalizableStrings.pl.xlf index 5c81b12ec..76006b1b9 100644 --- a/src/dotnet/commands/dotnet-list/dotnet-list-tool/xlf/LocalizableStrings.pl.xlf +++ b/src/dotnet/commands/dotnet-list/dotnet-list-tool/xlf/LocalizableStrings.pl.xlf @@ -12,11 +12,6 @@ List user wide tools. - - The --global switch (-g) is currently required because only user wide tools are supported. - The --global switch (-g) is currently required because only user wide tools are supported. - - Version Version @@ -37,6 +32,21 @@ Warning: tool package '{0}' is invalid: {1} + + Location where the tools are installed. + Location where the tools are installed. + + + + Please specify either the global option (--global) or the tool path option (--tool-path). + Please specify either the global option (--global) or the tool path option (--tool-path). + + + + (--global) conflicts with the tool path option (--tool-path). Please specify only one of the options. + (--global) conflicts with the tool path option (--tool-path). Please specify only one of the options. + + \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-list/dotnet-list-tool/xlf/LocalizableStrings.pt-BR.xlf b/src/dotnet/commands/dotnet-list/dotnet-list-tool/xlf/LocalizableStrings.pt-BR.xlf index 146703c1a..57dd7c6fe 100644 --- a/src/dotnet/commands/dotnet-list/dotnet-list-tool/xlf/LocalizableStrings.pt-BR.xlf +++ b/src/dotnet/commands/dotnet-list/dotnet-list-tool/xlf/LocalizableStrings.pt-BR.xlf @@ -12,11 +12,6 @@ List user wide tools. - - The --global switch (-g) is currently required because only user wide tools are supported. - The --global switch (-g) is currently required because only user wide tools are supported. - - Version Version @@ -37,6 +32,21 @@ Warning: tool package '{0}' is invalid: {1} + + Location where the tools are installed. + Location where the tools are installed. + + + + Please specify either the global option (--global) or the tool path option (--tool-path). + Please specify either the global option (--global) or the tool path option (--tool-path). + + + + (--global) conflicts with the tool path option (--tool-path). Please specify only one of the options. + (--global) conflicts with the tool path option (--tool-path). Please specify only one of the options. + + \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-list/dotnet-list-tool/xlf/LocalizableStrings.ru.xlf b/src/dotnet/commands/dotnet-list/dotnet-list-tool/xlf/LocalizableStrings.ru.xlf index dfda07a01..8e3b3f7b2 100644 --- a/src/dotnet/commands/dotnet-list/dotnet-list-tool/xlf/LocalizableStrings.ru.xlf +++ b/src/dotnet/commands/dotnet-list/dotnet-list-tool/xlf/LocalizableStrings.ru.xlf @@ -12,11 +12,6 @@ List user wide tools. - - The --global switch (-g) is currently required because only user wide tools are supported. - The --global switch (-g) is currently required because only user wide tools are supported. - - Version Version @@ -37,6 +32,21 @@ Warning: tool package '{0}' is invalid: {1} + + Location where the tools are installed. + Location where the tools are installed. + + + + Please specify either the global option (--global) or the tool path option (--tool-path). + Please specify either the global option (--global) or the tool path option (--tool-path). + + + + (--global) conflicts with the tool path option (--tool-path). Please specify only one of the options. + (--global) conflicts with the tool path option (--tool-path). Please specify only one of the options. + + \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-list/dotnet-list-tool/xlf/LocalizableStrings.tr.xlf b/src/dotnet/commands/dotnet-list/dotnet-list-tool/xlf/LocalizableStrings.tr.xlf index f51db1c10..f15578b16 100644 --- a/src/dotnet/commands/dotnet-list/dotnet-list-tool/xlf/LocalizableStrings.tr.xlf +++ b/src/dotnet/commands/dotnet-list/dotnet-list-tool/xlf/LocalizableStrings.tr.xlf @@ -12,11 +12,6 @@ List user wide tools. - - The --global switch (-g) is currently required because only user wide tools are supported. - The --global switch (-g) is currently required because only user wide tools are supported. - - Version Version @@ -37,6 +32,21 @@ Warning: tool package '{0}' is invalid: {1} + + Location where the tools are installed. + Location where the tools are installed. + + + + Please specify either the global option (--global) or the tool path option (--tool-path). + Please specify either the global option (--global) or the tool path option (--tool-path). + + + + (--global) conflicts with the tool path option (--tool-path). Please specify only one of the options. + (--global) conflicts with the tool path option (--tool-path). Please specify only one of the options. + + \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-list/dotnet-list-tool/xlf/LocalizableStrings.zh-Hans.xlf b/src/dotnet/commands/dotnet-list/dotnet-list-tool/xlf/LocalizableStrings.zh-Hans.xlf index 0473cd7d7..2a824d319 100644 --- a/src/dotnet/commands/dotnet-list/dotnet-list-tool/xlf/LocalizableStrings.zh-Hans.xlf +++ b/src/dotnet/commands/dotnet-list/dotnet-list-tool/xlf/LocalizableStrings.zh-Hans.xlf @@ -12,11 +12,6 @@ List user wide tools. - - The --global switch (-g) is currently required because only user wide tools are supported. - The --global switch (-g) is currently required because only user wide tools are supported. - - Version Version @@ -37,6 +32,21 @@ Warning: tool package '{0}' is invalid: {1} + + Location where the tools are installed. + Location where the tools are installed. + + + + Please specify either the global option (--global) or the tool path option (--tool-path). + Please specify either the global option (--global) or the tool path option (--tool-path). + + + + (--global) conflicts with the tool path option (--tool-path). Please specify only one of the options. + (--global) conflicts with the tool path option (--tool-path). Please specify only one of the options. + + \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-list/dotnet-list-tool/xlf/LocalizableStrings.zh-Hant.xlf b/src/dotnet/commands/dotnet-list/dotnet-list-tool/xlf/LocalizableStrings.zh-Hant.xlf index 34eadedae..f54b5933d 100644 --- a/src/dotnet/commands/dotnet-list/dotnet-list-tool/xlf/LocalizableStrings.zh-Hant.xlf +++ b/src/dotnet/commands/dotnet-list/dotnet-list-tool/xlf/LocalizableStrings.zh-Hant.xlf @@ -12,11 +12,6 @@ List user wide tools. - - The --global switch (-g) is currently required because only user wide tools are supported. - The --global switch (-g) is currently required because only user wide tools are supported. - - Version Version @@ -37,6 +32,21 @@ Warning: tool package '{0}' is invalid: {1} + + Location where the tools are installed. + Location where the tools are installed. + + + + Please specify either the global option (--global) or the tool path option (--tool-path). + Please specify either the global option (--global) or the tool path option (--tool-path). + + + + (--global) conflicts with the tool path option (--tool-path). Please specify only one of the options. + (--global) conflicts with the tool path option (--tool-path). Please specify only one of the options. + + \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-uninstall/tool/UninstallToolCommand.cs b/src/dotnet/commands/dotnet-uninstall/tool/UninstallToolCommand.cs index 11cd9dd98..87661cced 100644 --- a/src/dotnet/commands/dotnet-uninstall/tool/UninstallToolCommand.cs +++ b/src/dotnet/commands/dotnet-uninstall/tool/UninstallToolCommand.cs @@ -24,12 +24,12 @@ namespace Microsoft.DotNet.Tools.Uninstall.Tool private readonly IReporter _reporter; private readonly IReporter _errorReporter; private CreateShellShimRepository _createShellShimRepository; - private CreateToolPackageStore _createToolPackageStoreAndInstaller; + private CreateToolPackageStore _createToolPackageStore; public UninstallToolCommand( AppliedOption options, ParseResult result, - CreateToolPackageStore createToolPackageStoreAndInstaller = null, + CreateToolPackageStore createToolPackageStore = null, CreateShellShimRepository createShellShimRepository = null, IReporter reporter = null) : base(result) @@ -41,7 +41,7 @@ namespace Microsoft.DotNet.Tools.Uninstall.Tool _errorReporter = reporter ?? Reporter.Error; _createShellShimRepository = createShellShimRepository ?? ShellShimRepositoryFactory.CreateShellShimRepository; - _createToolPackageStoreAndInstaller = createToolPackageStoreAndInstaller ?? ToolPackageFactory.CreateToolPackageStore; + _createToolPackageStore = createToolPackageStore ?? ToolPackageFactory.CreateToolPackageStore; } public override int Execute() @@ -65,7 +65,7 @@ namespace Microsoft.DotNet.Tools.Uninstall.Tool toolDirectoryPath = new DirectoryPath(toolPath); } - IToolPackageStore toolPackageStore = _createToolPackageStoreAndInstaller(toolDirectoryPath); + IToolPackageStore toolPackageStore = _createToolPackageStore(toolDirectoryPath); IShellShimRepository shellShimRepository = _createShellShimRepository(toolDirectoryPath); var packageId = new PackageId(_options.Arguments.Single()); diff --git a/test/dotnet.Tests/CommandTests/ListToolCommandTests.cs b/test/dotnet.Tests/CommandTests/ListToolCommandTests.cs index c378e0803..879f37870 100644 --- a/test/dotnet.Tests/CommandTests/ListToolCommandTests.cs +++ b/test/dotnet.Tests/CommandTests/ListToolCommandTests.cs @@ -33,7 +33,7 @@ namespace Microsoft.DotNet.Tests.Commands } [Fact] - public void GivenAMissingGlobalOptionItErrors() + public void GivenAMissingGlobalOrToolPathOptionItErrors() { var store = new Mock(MockBehavior.Strict); @@ -47,7 +47,25 @@ namespace Microsoft.DotNet.Tests.Commands .And .Message .Should() - .Be(LocalizableStrings.ListToolCommandOnlySupportsGlobal); + .Be(LocalizableStrings.NeedGlobalOrToolPath); + } + + [Fact] + public void GivenBothGlobalAndToolPathOptionsItErrors() + { + var store = new Mock(MockBehavior.Strict); + + var command = CreateCommand(store.Object, "-g --tool-path /tools", "/tools"); + + Action a = () => { + command.Execute(); + }; + + a.ShouldThrow() + .And + .Message + .Should() + .Be(LocalizableStrings.GlobalAndToolPathConflict); } [Fact] @@ -65,6 +83,21 @@ namespace Microsoft.DotNet.Tests.Commands _reporter.Lines.Should().Equal(EnumerateExpectedTableLines(store.Object)); } + [Fact] + public void GivenAToolPathItPassesToolPathToStoreFactory() + { + var store = new Mock(MockBehavior.Strict); + store + .Setup(s => s.EnumeratePackages()) + .Returns(new IToolPackage[0]); + + var command = CreateCommand(store.Object, "--tool-path /tools", "/tools"); + + command.Execute().Should().Be(0); + + _reporter.Lines.Should().Equal(EnumerateExpectedTableLines(store.Object)); + } + [Fact] public void GivenASingleInstalledPackageItPrintsThePackage() { @@ -206,16 +239,29 @@ namespace Microsoft.DotNet.Tests.Commands return package.Object; } - private ListToolCommand CreateCommand(IToolPackageStore store, string options = "") + private ListToolCommand CreateCommand(IToolPackageStore store, string options = "", string expectedToolPath = null) { ParseResult result = Parser.Instance.Parse("dotnet list tool " + options); return new ListToolCommand( result["dotnet"]["list"]["tool"], result, - store, + toolPath => { AssertExpectedToolPath(toolPath, expectedToolPath); return store; }, _reporter); } + private void AssertExpectedToolPath(DirectoryPath? toolPath, string expectedToolPath) + { + if (expectedToolPath != null) + { + toolPath.Should().NotBeNull(); + toolPath.Value.Value.Should().Be(expectedToolPath); + } + else + { + toolPath.Should().BeNull(); + } + } + private IEnumerable EnumerateExpectedTableLines(IToolPackageStore store) { string GetCommandsString(IToolPackage package) diff --git a/test/dotnet.Tests/ParserTests/InstallToolParserTests.cs b/test/dotnet.Tests/ParserTests/InstallToolParserTests.cs index 1c9b54e64..191231821 100644 --- a/test/dotnet.Tests/ParserTests/InstallToolParserTests.cs +++ b/test/dotnet.Tests/ParserTests/InstallToolParserTests.cs @@ -84,10 +84,10 @@ namespace Microsoft.DotNet.Tests.ParserTests public void InstallToolParserCanParseToolPathOption() { var result = - Parser.Instance.Parse(@"dotnet install tool --tool-path C:\TestAssetLocalNugetFeed console.test.app"); + Parser.Instance.Parse(@"dotnet install tool --tool-path C:\Tools console.test.app"); var appliedOptions = result["dotnet"]["install"]["tool"]; - appliedOptions.SingleArgumentOrDefault("tool-path").Should().Be(@"C:\TestAssetLocalNugetFeed"); + appliedOptions.SingleArgumentOrDefault("tool-path").Should().Be(@"C:\Tools"); } } } diff --git a/test/dotnet.Tests/ParserTests/ListToolParserTests.cs b/test/dotnet.Tests/ParserTests/ListToolParserTests.cs new file mode 100644 index 000000000..b538f8eab --- /dev/null +++ b/test/dotnet.Tests/ParserTests/ListToolParserTests.cs @@ -0,0 +1,42 @@ +// 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 FluentAssertions; +using Microsoft.DotNet.Cli; +using Microsoft.DotNet.Cli.CommandLine; +using Xunit; +using Xunit.Abstractions; +using Parser = Microsoft.DotNet.Cli.Parser; + +namespace Microsoft.DotNet.Tests.ParserTests +{ + public class ListToolParserTests + { + private readonly ITestOutputHelper output; + + public ListToolParserTests(ITestOutputHelper output) + { + this.output = output; + } + + [Fact] + public void ListToolParserCanGetGlobalOption() + { + var result = Parser.Instance.Parse("dotnet list tool -g"); + + var appliedOptions = result["dotnet"]["list"]["tool"]; + appliedOptions.ValueOrDefault("global").Should().Be(true); + } + + [Fact] + public void ListToolParserCanParseToolPathOption() + { + var result = + Parser.Instance.Parse(@"dotnet list tool --tool-path C:\Tools "); + + var appliedOptions = result["dotnet"]["list"]["tool"]; + appliedOptions.SingleArgumentOrDefault("tool-path").Should().Be(@"C:\Tools"); + } + } +} diff --git a/test/dotnet.Tests/ParserTests/UninstallInstallToolParserTests.cs b/test/dotnet.Tests/ParserTests/UninstallToolParserTests.cs similarity index 84% rename from test/dotnet.Tests/ParserTests/UninstallInstallToolParserTests.cs rename to test/dotnet.Tests/ParserTests/UninstallToolParserTests.cs index ab1581f5d..ace3874d4 100644 --- a/test/dotnet.Tests/ParserTests/UninstallInstallToolParserTests.cs +++ b/test/dotnet.Tests/ParserTests/UninstallToolParserTests.cs @@ -11,17 +11,17 @@ using Parser = Microsoft.DotNet.Cli.Parser; namespace Microsoft.DotNet.Tests.ParserTests { - public class UninstallInstallToolParserTests + public class UninstallToolParserTests { private readonly ITestOutputHelper output; - public UninstallInstallToolParserTests(ITestOutputHelper output) + public UninstallToolParserTests(ITestOutputHelper output) { this.output = output; } [Fact] - public void UninstallGlobaltoolParserCanGetPackageId() + public void UninstallToolParserCanGetPackageId() { var command = Parser.Instance; var result = command.Parse("dotnet uninstall tool -g console.test.app"); @@ -46,10 +46,10 @@ namespace Microsoft.DotNet.Tests.ParserTests public void UninstallToolParserCanParseToolPathOption() { var result = - Parser.Instance.Parse(@"dotnet uninstall tool --tool-path C:\TestAssetLocalNugetFeed console.test.app"); + Parser.Instance.Parse(@"dotnet uninstall tool --tool-path C:\Tools console.test.app"); var appliedOptions = result["dotnet"]["uninstall"]["tool"]; - appliedOptions.SingleArgumentOrDefault("tool-path").Should().Be(@"C:\TestAssetLocalNugetFeed"); + appliedOptions.SingleArgumentOrDefault("tool-path").Should().Be(@"C:\Tools"); } } }