Merge pull request #8830 from peterhuene/list-tool-path

Implement the --tool-path option for list tool command.
This commit is contained in:
Peter Huene 2018-03-19 08:36:51 -07:00 committed by GitHub
commit ec3bdf693c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 343 additions and 96 deletions

View file

@ -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; }

View file

@ -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<bool>("global"))
var global = _options.ValueOrDefault<bool>("global");
var toolPathOption = _options.ValueOrDefault<string>("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<IToolPackage>();
@ -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<IToolPackage> GetPackages()
private IEnumerable<IToolPackage> GetPackages(DirectoryPath? toolPath)
{
return _toolPackageStore.EnumeratePackages()
return _createToolPackageStore(toolPath).EnumeratePackages()
.Where(PackageHasCommands)
.OrderBy(p => p.Id)
.ToArray();

View file

@ -17,6 +17,10 @@ namespace Microsoft.DotNet.Cli
"-g|--global",
LocalizableStrings.GlobalOptionDescription,
Accept.NoArguments()),
Create.Option(
"--tool-path",
LocalizableStrings.ToolPathDescription,
Accept.ExactlyOneArgument()),
CommonOptions.HelpOption());
}
}

View file

@ -123,8 +123,14 @@
<data name="GlobalOptionDescription" xml:space="preserve">
<value>List user wide tools.</value>
</data>
<data name="ListToolCommandOnlySupportsGlobal" xml:space="preserve">
<value>The --global switch (-g) is currently required because only user wide tools are supported.</value>
<data name="ToolPathDescription" xml:space="preserve">
<value>Location where the tools are installed.</value>
</data>
<data name="NeedGlobalOrToolPath" xml:space="preserve">
<value>Please specify either the global option (--global) or the tool path option (--tool-path).</value>
</data>
<data name="GlobalAndToolPathConflict" xml:space="preserve">
<value>(--global) conflicts with the tool path option (--tool-path). Please specify only one of the options.</value>
</data>
<data name="InvalidPackageWarning" xml:space="preserve">
<value>Warning: tool package '{0}' is invalid: {1}</value>

View file

@ -12,11 +12,6 @@
<target state="new">List user wide tools.</target>
<note />
</trans-unit>
<trans-unit id="ListToolCommandOnlySupportsGlobal">
<source>The --global switch (-g) is currently required because only user wide tools are supported.</source>
<target state="new">The --global switch (-g) is currently required because only user wide tools are supported.</target>
<note />
</trans-unit>
<trans-unit id="VersionColumn">
<source>Version</source>
<target state="new">Version</target>
@ -37,6 +32,21 @@
<target state="new">Warning: tool package '{0}' is invalid: {1}</target>
<note />
</trans-unit>
<trans-unit id="ToolPathDescription">
<source>Location where the tools are installed.</source>
<target state="new">Location where the tools are installed.</target>
<note />
</trans-unit>
<trans-unit id="NeedGlobalOrToolPath">
<source>Please specify either the global option (--global) or the tool path option (--tool-path).</source>
<target state="new">Please specify either the global option (--global) or the tool path option (--tool-path).</target>
<note />
</trans-unit>
<trans-unit id="GlobalAndToolPathConflict">
<source>(--global) conflicts with the tool path option (--tool-path). Please specify only one of the options.</source>
<target state="new">(--global) conflicts with the tool path option (--tool-path). Please specify only one of the options.</target>
<note />
</trans-unit>
</body>
</file>
</xliff>

View file

@ -12,11 +12,6 @@
<target state="new">List user wide tools.</target>
<note />
</trans-unit>
<trans-unit id="ListToolCommandOnlySupportsGlobal">
<source>The --global switch (-g) is currently required because only user wide tools are supported.</source>
<target state="new">The --global switch (-g) is currently required because only user wide tools are supported.</target>
<note />
</trans-unit>
<trans-unit id="VersionColumn">
<source>Version</source>
<target state="new">Version</target>
@ -37,6 +32,21 @@
<target state="new">Warning: tool package '{0}' is invalid: {1}</target>
<note />
</trans-unit>
<trans-unit id="ToolPathDescription">
<source>Location where the tools are installed.</source>
<target state="new">Location where the tools are installed.</target>
<note />
</trans-unit>
<trans-unit id="NeedGlobalOrToolPath">
<source>Please specify either the global option (--global) or the tool path option (--tool-path).</source>
<target state="new">Please specify either the global option (--global) or the tool path option (--tool-path).</target>
<note />
</trans-unit>
<trans-unit id="GlobalAndToolPathConflict">
<source>(--global) conflicts with the tool path option (--tool-path). Please specify only one of the options.</source>
<target state="new">(--global) conflicts with the tool path option (--tool-path). Please specify only one of the options.</target>
<note />
</trans-unit>
</body>
</file>
</xliff>

View file

@ -12,11 +12,6 @@
<target state="new">List user wide tools.</target>
<note />
</trans-unit>
<trans-unit id="ListToolCommandOnlySupportsGlobal">
<source>The --global switch (-g) is currently required because only user wide tools are supported.</source>
<target state="new">The --global switch (-g) is currently required because only user wide tools are supported.</target>
<note />
</trans-unit>
<trans-unit id="VersionColumn">
<source>Version</source>
<target state="new">Version</target>
@ -37,6 +32,21 @@
<target state="new">Warning: tool package '{0}' is invalid: {1}</target>
<note />
</trans-unit>
<trans-unit id="ToolPathDescription">
<source>Location where the tools are installed.</source>
<target state="new">Location where the tools are installed.</target>
<note />
</trans-unit>
<trans-unit id="NeedGlobalOrToolPath">
<source>Please specify either the global option (--global) or the tool path option (--tool-path).</source>
<target state="new">Please specify either the global option (--global) or the tool path option (--tool-path).</target>
<note />
</trans-unit>
<trans-unit id="GlobalAndToolPathConflict">
<source>(--global) conflicts with the tool path option (--tool-path). Please specify only one of the options.</source>
<target state="new">(--global) conflicts with the tool path option (--tool-path). Please specify only one of the options.</target>
<note />
</trans-unit>
</body>
</file>
</xliff>

View file

@ -12,11 +12,6 @@
<target state="new">List user wide tools.</target>
<note />
</trans-unit>
<trans-unit id="ListToolCommandOnlySupportsGlobal">
<source>The --global switch (-g) is currently required because only user wide tools are supported.</source>
<target state="new">The --global switch (-g) is currently required because only user wide tools are supported.</target>
<note />
</trans-unit>
<trans-unit id="VersionColumn">
<source>Version</source>
<target state="new">Version</target>
@ -37,6 +32,21 @@
<target state="new">Warning: tool package '{0}' is invalid: {1}</target>
<note />
</trans-unit>
<trans-unit id="ToolPathDescription">
<source>Location where the tools are installed.</source>
<target state="new">Location where the tools are installed.</target>
<note />
</trans-unit>
<trans-unit id="NeedGlobalOrToolPath">
<source>Please specify either the global option (--global) or the tool path option (--tool-path).</source>
<target state="new">Please specify either the global option (--global) or the tool path option (--tool-path).</target>
<note />
</trans-unit>
<trans-unit id="GlobalAndToolPathConflict">
<source>(--global) conflicts with the tool path option (--tool-path). Please specify only one of the options.</source>
<target state="new">(--global) conflicts with the tool path option (--tool-path). Please specify only one of the options.</target>
<note />
</trans-unit>
</body>
</file>
</xliff>

View file

@ -12,11 +12,6 @@
<target state="new">List user wide tools.</target>
<note />
</trans-unit>
<trans-unit id="ListToolCommandOnlySupportsGlobal">
<source>The --global switch (-g) is currently required because only user wide tools are supported.</source>
<target state="new">The --global switch (-g) is currently required because only user wide tools are supported.</target>
<note />
</trans-unit>
<trans-unit id="VersionColumn">
<source>Version</source>
<target state="new">Version</target>
@ -37,6 +32,21 @@
<target state="new">Warning: tool package '{0}' is invalid: {1}</target>
<note />
</trans-unit>
<trans-unit id="ToolPathDescription">
<source>Location where the tools are installed.</source>
<target state="new">Location where the tools are installed.</target>
<note />
</trans-unit>
<trans-unit id="NeedGlobalOrToolPath">
<source>Please specify either the global option (--global) or the tool path option (--tool-path).</source>
<target state="new">Please specify either the global option (--global) or the tool path option (--tool-path).</target>
<note />
</trans-unit>
<trans-unit id="GlobalAndToolPathConflict">
<source>(--global) conflicts with the tool path option (--tool-path). Please specify only one of the options.</source>
<target state="new">(--global) conflicts with the tool path option (--tool-path). Please specify only one of the options.</target>
<note />
</trans-unit>
</body>
</file>
</xliff>

View file

@ -12,11 +12,6 @@
<target state="new">List user wide tools.</target>
<note />
</trans-unit>
<trans-unit id="ListToolCommandOnlySupportsGlobal">
<source>The --global switch (-g) is currently required because only user wide tools are supported.</source>
<target state="new">The --global switch (-g) is currently required because only user wide tools are supported.</target>
<note />
</trans-unit>
<trans-unit id="VersionColumn">
<source>Version</source>
<target state="new">Version</target>
@ -37,6 +32,21 @@
<target state="new">Warning: tool package '{0}' is invalid: {1}</target>
<note />
</trans-unit>
<trans-unit id="ToolPathDescription">
<source>Location where the tools are installed.</source>
<target state="new">Location where the tools are installed.</target>
<note />
</trans-unit>
<trans-unit id="NeedGlobalOrToolPath">
<source>Please specify either the global option (--global) or the tool path option (--tool-path).</source>
<target state="new">Please specify either the global option (--global) or the tool path option (--tool-path).</target>
<note />
</trans-unit>
<trans-unit id="GlobalAndToolPathConflict">
<source>(--global) conflicts with the tool path option (--tool-path). Please specify only one of the options.</source>
<target state="new">(--global) conflicts with the tool path option (--tool-path). Please specify only one of the options.</target>
<note />
</trans-unit>
</body>
</file>
</xliff>

View file

@ -12,11 +12,6 @@
<target state="new">List user wide tools.</target>
<note />
</trans-unit>
<trans-unit id="ListToolCommandOnlySupportsGlobal">
<source>The --global switch (-g) is currently required because only user wide tools are supported.</source>
<target state="new">The --global switch (-g) is currently required because only user wide tools are supported.</target>
<note />
</trans-unit>
<trans-unit id="VersionColumn">
<source>Version</source>
<target state="new">Version</target>
@ -37,6 +32,21 @@
<target state="new">Warning: tool package '{0}' is invalid: {1}</target>
<note />
</trans-unit>
<trans-unit id="ToolPathDescription">
<source>Location where the tools are installed.</source>
<target state="new">Location where the tools are installed.</target>
<note />
</trans-unit>
<trans-unit id="NeedGlobalOrToolPath">
<source>Please specify either the global option (--global) or the tool path option (--tool-path).</source>
<target state="new">Please specify either the global option (--global) or the tool path option (--tool-path).</target>
<note />
</trans-unit>
<trans-unit id="GlobalAndToolPathConflict">
<source>(--global) conflicts with the tool path option (--tool-path). Please specify only one of the options.</source>
<target state="new">(--global) conflicts with the tool path option (--tool-path). Please specify only one of the options.</target>
<note />
</trans-unit>
</body>
</file>
</xliff>

View file

@ -12,11 +12,6 @@
<target state="new">List user wide tools.</target>
<note />
</trans-unit>
<trans-unit id="ListToolCommandOnlySupportsGlobal">
<source>The --global switch (-g) is currently required because only user wide tools are supported.</source>
<target state="new">The --global switch (-g) is currently required because only user wide tools are supported.</target>
<note />
</trans-unit>
<trans-unit id="VersionColumn">
<source>Version</source>
<target state="new">Version</target>
@ -37,6 +32,21 @@
<target state="new">Warning: tool package '{0}' is invalid: {1}</target>
<note />
</trans-unit>
<trans-unit id="ToolPathDescription">
<source>Location where the tools are installed.</source>
<target state="new">Location where the tools are installed.</target>
<note />
</trans-unit>
<trans-unit id="NeedGlobalOrToolPath">
<source>Please specify either the global option (--global) or the tool path option (--tool-path).</source>
<target state="new">Please specify either the global option (--global) or the tool path option (--tool-path).</target>
<note />
</trans-unit>
<trans-unit id="GlobalAndToolPathConflict">
<source>(--global) conflicts with the tool path option (--tool-path). Please specify only one of the options.</source>
<target state="new">(--global) conflicts with the tool path option (--tool-path). Please specify only one of the options.</target>
<note />
</trans-unit>
</body>
</file>
</xliff>

View file

@ -12,11 +12,6 @@
<target state="new">List user wide tools.</target>
<note />
</trans-unit>
<trans-unit id="ListToolCommandOnlySupportsGlobal">
<source>The --global switch (-g) is currently required because only user wide tools are supported.</source>
<target state="new">The --global switch (-g) is currently required because only user wide tools are supported.</target>
<note />
</trans-unit>
<trans-unit id="VersionColumn">
<source>Version</source>
<target state="new">Version</target>
@ -37,6 +32,21 @@
<target state="new">Warning: tool package '{0}' is invalid: {1}</target>
<note />
</trans-unit>
<trans-unit id="ToolPathDescription">
<source>Location where the tools are installed.</source>
<target state="new">Location where the tools are installed.</target>
<note />
</trans-unit>
<trans-unit id="NeedGlobalOrToolPath">
<source>Please specify either the global option (--global) or the tool path option (--tool-path).</source>
<target state="new">Please specify either the global option (--global) or the tool path option (--tool-path).</target>
<note />
</trans-unit>
<trans-unit id="GlobalAndToolPathConflict">
<source>(--global) conflicts with the tool path option (--tool-path). Please specify only one of the options.</source>
<target state="new">(--global) conflicts with the tool path option (--tool-path). Please specify only one of the options.</target>
<note />
</trans-unit>
</body>
</file>
</xliff>

View file

@ -12,11 +12,6 @@
<target state="new">List user wide tools.</target>
<note />
</trans-unit>
<trans-unit id="ListToolCommandOnlySupportsGlobal">
<source>The --global switch (-g) is currently required because only user wide tools are supported.</source>
<target state="new">The --global switch (-g) is currently required because only user wide tools are supported.</target>
<note />
</trans-unit>
<trans-unit id="VersionColumn">
<source>Version</source>
<target state="new">Version</target>
@ -37,6 +32,21 @@
<target state="new">Warning: tool package '{0}' is invalid: {1}</target>
<note />
</trans-unit>
<trans-unit id="ToolPathDescription">
<source>Location where the tools are installed.</source>
<target state="new">Location where the tools are installed.</target>
<note />
</trans-unit>
<trans-unit id="NeedGlobalOrToolPath">
<source>Please specify either the global option (--global) or the tool path option (--tool-path).</source>
<target state="new">Please specify either the global option (--global) or the tool path option (--tool-path).</target>
<note />
</trans-unit>
<trans-unit id="GlobalAndToolPathConflict">
<source>(--global) conflicts with the tool path option (--tool-path). Please specify only one of the options.</source>
<target state="new">(--global) conflicts with the tool path option (--tool-path). Please specify only one of the options.</target>
<note />
</trans-unit>
</body>
</file>
</xliff>

View file

@ -12,11 +12,6 @@
<target state="new">List user wide tools.</target>
<note />
</trans-unit>
<trans-unit id="ListToolCommandOnlySupportsGlobal">
<source>The --global switch (-g) is currently required because only user wide tools are supported.</source>
<target state="new">The --global switch (-g) is currently required because only user wide tools are supported.</target>
<note />
</trans-unit>
<trans-unit id="VersionColumn">
<source>Version</source>
<target state="new">Version</target>
@ -37,6 +32,21 @@
<target state="new">Warning: tool package '{0}' is invalid: {1}</target>
<note />
</trans-unit>
<trans-unit id="ToolPathDescription">
<source>Location where the tools are installed.</source>
<target state="new">Location where the tools are installed.</target>
<note />
</trans-unit>
<trans-unit id="NeedGlobalOrToolPath">
<source>Please specify either the global option (--global) or the tool path option (--tool-path).</source>
<target state="new">Please specify either the global option (--global) or the tool path option (--tool-path).</target>
<note />
</trans-unit>
<trans-unit id="GlobalAndToolPathConflict">
<source>(--global) conflicts with the tool path option (--tool-path). Please specify only one of the options.</source>
<target state="new">(--global) conflicts with the tool path option (--tool-path). Please specify only one of the options.</target>
<note />
</trans-unit>
</body>
</file>
</xliff>

View file

@ -12,11 +12,6 @@
<target state="new">List user wide tools.</target>
<note />
</trans-unit>
<trans-unit id="ListToolCommandOnlySupportsGlobal">
<source>The --global switch (-g) is currently required because only user wide tools are supported.</source>
<target state="new">The --global switch (-g) is currently required because only user wide tools are supported.</target>
<note />
</trans-unit>
<trans-unit id="VersionColumn">
<source>Version</source>
<target state="new">Version</target>
@ -37,6 +32,21 @@
<target state="new">Warning: tool package '{0}' is invalid: {1}</target>
<note />
</trans-unit>
<trans-unit id="ToolPathDescription">
<source>Location where the tools are installed.</source>
<target state="new">Location where the tools are installed.</target>
<note />
</trans-unit>
<trans-unit id="NeedGlobalOrToolPath">
<source>Please specify either the global option (--global) or the tool path option (--tool-path).</source>
<target state="new">Please specify either the global option (--global) or the tool path option (--tool-path).</target>
<note />
</trans-unit>
<trans-unit id="GlobalAndToolPathConflict">
<source>(--global) conflicts with the tool path option (--tool-path). Please specify only one of the options.</source>
<target state="new">(--global) conflicts with the tool path option (--tool-path). Please specify only one of the options.</target>
<note />
</trans-unit>
</body>
</file>
</xliff>

View file

@ -12,11 +12,6 @@
<target state="new">List user wide tools.</target>
<note />
</trans-unit>
<trans-unit id="ListToolCommandOnlySupportsGlobal">
<source>The --global switch (-g) is currently required because only user wide tools are supported.</source>
<target state="new">The --global switch (-g) is currently required because only user wide tools are supported.</target>
<note />
</trans-unit>
<trans-unit id="VersionColumn">
<source>Version</source>
<target state="new">Version</target>
@ -37,6 +32,21 @@
<target state="new">Warning: tool package '{0}' is invalid: {1}</target>
<note />
</trans-unit>
<trans-unit id="ToolPathDescription">
<source>Location where the tools are installed.</source>
<target state="new">Location where the tools are installed.</target>
<note />
</trans-unit>
<trans-unit id="NeedGlobalOrToolPath">
<source>Please specify either the global option (--global) or the tool path option (--tool-path).</source>
<target state="new">Please specify either the global option (--global) or the tool path option (--tool-path).</target>
<note />
</trans-unit>
<trans-unit id="GlobalAndToolPathConflict">
<source>(--global) conflicts with the tool path option (--tool-path). Please specify only one of the options.</source>
<target state="new">(--global) conflicts with the tool path option (--tool-path). Please specify only one of the options.</target>
<note />
</trans-unit>
</body>
</file>
</xliff>

View file

@ -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());

View file

@ -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);
}

View file

@ -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;
}

View file

@ -33,7 +33,7 @@ namespace Microsoft.DotNet.Tests.Commands
}
[Fact]
public void GivenAMissingGlobalOptionItErrors()
public void GivenAMissingGlobalOrToolPathOptionItErrors()
{
var store = new Mock<IToolPackageStore>(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<IToolPackageStore>(MockBehavior.Strict);
var command = CreateCommand(store.Object, "-g --tool-path /tools", "/tools");
Action a = () => {
command.Execute();
};
a.ShouldThrow<GracefulException>()
.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<IToolPackageStore>(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<string> EnumerateExpectedTableLines(IToolPackageStore store)
{
string GetCommandsString(IToolPackage package)

View file

@ -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 +

View file

@ -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");
}
}
}

View file

@ -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<bool>("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");
}
}
}

View file

@ -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");
}
}
}