Implement uninstall tool command.

This commit implements the `uninstall tool` command.

The `uninstall tool` command is responsible for uninstalling global tools that
are installed with the `install tool` command.

This commit heavily refactors the ToolPackage and ShellShim namespaces to
better support the operations required for the uninstall command.

Several string resources have been updated to be more informative or to correct
oddly structured sentences.

This commit also fixes `--version` on the install command not supporting ranges
and wildcards.

Fixes #8549.

Issue #8485 is partially fixed by this commit (`--prerelease` is not yet
implemented).
This commit is contained in:
Peter Huene 2018-01-28 13:35:04 -08:00
commit aab9af71b8
No known key found for this signature in database
GPG key ID: E1D265D820213D6A
134 changed files with 6376 additions and 3159 deletions

View file

@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.Extensions.EnvironmentAbstractions;
namespace Microsoft.DotNet.ToolPackage
{
internal class ToolPackageStore : IToolPackageStore
{
public ToolPackageStore(DirectoryPath root)
{
Root = root;
}
public DirectoryPath Root { get; private set; }
public IEnumerable<IToolPackage> GetInstalledPackages(string packageId)
{
if (packageId == null)
{
throw new ArgumentNullException(nameof(packageId));
}
var packageRootDirectory = Root.WithSubDirectories(packageId);
if (!Directory.Exists(packageRootDirectory.Value))
{
yield break;
}
foreach (var subdirectory in Directory.EnumerateDirectories(packageRootDirectory.Value))
{
var version = Path.GetFileName(subdirectory);
yield return new ToolPackageInstance(
this,
packageId,
version,
packageRootDirectory.WithSubDirectories(version));
}
}
}
}