Implement list tool
command.
This commit implements the `list tool` command. The command is responsible for displaying a list of install global tools. Fixes #8548.
This commit is contained in:
parent
9ef495327a
commit
4490fd5aa8
56 changed files with 1043 additions and 200 deletions
|
@ -15,13 +15,37 @@ namespace Microsoft.DotNet.ToolPackage
|
|||
|
||||
public DirectoryPath Root { get; private set; }
|
||||
|
||||
public IEnumerable<IToolPackage> GetInstalledPackages(string packageId)
|
||||
public IEnumerable<IToolPackage> GetInstalledPackages(string packageId = null)
|
||||
{
|
||||
if (packageId == null)
|
||||
if (packageId != null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(packageId));
|
||||
return EnumerateVersions(packageId);
|
||||
}
|
||||
|
||||
return EnumerateAllPackages().SelectMany(p => p);
|
||||
}
|
||||
|
||||
private IEnumerable<IEnumerable<IToolPackage>> EnumerateAllPackages()
|
||||
{
|
||||
if (!Directory.Exists(Root.Value))
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
|
||||
foreach (var subdirectory in Directory.EnumerateDirectories(Root.Value))
|
||||
{
|
||||
var packageId = Path.GetFileName(subdirectory);
|
||||
if (packageId == ToolPackageInstaller.StagingDirectory)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
yield return EnumerateVersions(packageId);
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerable<IToolPackage> EnumerateVersions(string packageId)
|
||||
{
|
||||
var packageRootDirectory = Root.WithSubDirectories(packageId);
|
||||
if (!Directory.Exists(packageRootDirectory.Value))
|
||||
{
|
||||
|
|
Reference in a new issue