Skip to content
This repository was archived by the owner on Apr 20, 2023. It is now read-only.

Commit 4490fd5

Browse files
author
Peter Huene
committed
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.
1 parent 9ef4953 commit 4490fd5

File tree

56 files changed

+1043
-200
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1043
-200
lines changed

src/dotnet/CommonLocalizableStrings.resx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -610,11 +610,11 @@ setx PATH "%PATH%;{0}"
610610
<data name="FailedToUninstallToolPackage" xml:space="preserve">
611611
<value>Failed to uninstall tool package '{0}': {1}</value>
612612
</data>
613-
<data name="ToolPackageMissingEntryPointFile" xml:space="preserve">
614-
<value>Package '{0}' is missing entry point file {1}.</value>
613+
<data name="MissingToolEntryPointFile" xml:space="preserve">
614+
<value>Entry point file '{0}' for command '{1}' was not found in the package.</value>
615615
</data>
616-
<data name="ToolPackageMissingSettingsFile" xml:space="preserve">
617-
<value>Package '{0}' is missing tool settings file DotnetToolSettings.xml.</value>
616+
<data name="MissingToolSettingsFile" xml:space="preserve">
617+
<value>Settings file 'DotnetToolSettings.xml' was not found in the package.</value>
618618
</data>
619619
<data name="ToolPackageConflictPackageId" xml:space="preserve">
620620
<value>Tool '{0}' (version '{1}') is already installed.</value>

src/dotnet/ToolPackage/IToolPackageStore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ internal interface IToolPackageStore
1111
{
1212
DirectoryPath Root { get; }
1313

14-
IEnumerable<IToolPackage> GetInstalledPackages(string packageId);
14+
IEnumerable<IToolPackage> GetInstalledPackages(string packageId = null);
1515
}
1616
}

src/dotnet/ToolPackage/ToolPackageInstance.cs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,8 @@ private IReadOnlyList<CommandSettings> GetCommands()
109109
var dotnetToolSettings = FindItemInTargetLibrary(library, ToolSettingsFileName);
110110
if (dotnetToolSettings == null)
111111
{
112-
throw new ToolPackageException(
113-
string.Format(
114-
CommonLocalizableStrings.ToolPackageMissingSettingsFile,
115-
PackageId));
112+
throw new ToolConfigurationException(
113+
CommonLocalizableStrings.MissingToolSettingsFile);
116114
}
117115

118116
var toolConfigurationPath =
@@ -127,11 +125,11 @@ private IReadOnlyList<CommandSettings> GetCommands()
127125
var entryPointFromLockFile = FindItemInTargetLibrary(library, configuration.ToolAssemblyEntryPoint);
128126
if (entryPointFromLockFile == null)
129127
{
130-
throw new ToolPackageException(
128+
throw new ToolConfigurationException(
131129
string.Format(
132-
CommonLocalizableStrings.ToolPackageMissingEntryPointFile,
133-
PackageId,
134-
configuration.ToolAssemblyEntryPoint));
130+
CommonLocalizableStrings.MissingToolEntryPointFile,
131+
configuration.ToolAssemblyEntryPoint,
132+
configuration.CommandName));
135133
}
136134

137135
// Currently only "dotnet" commands are supported
@@ -148,10 +146,9 @@ private IReadOnlyList<CommandSettings> GetCommands()
148146
}
149147
catch (Exception ex) when (ex is UnauthorizedAccessException || ex is IOException)
150148
{
151-
throw new ToolPackageException(
149+
throw new ToolConfigurationException(
152150
string.Format(
153151
CommonLocalizableStrings.FailedToRetrieveToolConfiguration,
154-
PackageId,
155152
ex.Message),
156153
ex);
157154
}

src/dotnet/ToolPackage/ToolPackageStore.cs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,37 @@ public ToolPackageStore(DirectoryPath root)
1515

1616
public DirectoryPath Root { get; private set; }
1717

18-
public IEnumerable<IToolPackage> GetInstalledPackages(string packageId)
18+
public IEnumerable<IToolPackage> GetInstalledPackages(string packageId = null)
1919
{
20-
if (packageId == null)
20+
if (packageId != null)
2121
{
22-
throw new ArgumentNullException(nameof(packageId));
22+
return EnumerateVersions(packageId);
2323
}
2424

25+
return EnumerateAllPackages().SelectMany(p => p);
26+
}
27+
28+
private IEnumerable<IEnumerable<IToolPackage>> EnumerateAllPackages()
29+
{
30+
if (!Directory.Exists(Root.Value))
31+
{
32+
yield break;
33+
}
34+
35+
foreach (var subdirectory in Directory.EnumerateDirectories(Root.Value))
36+
{
37+
var packageId = Path.GetFileName(subdirectory);
38+
if (packageId == ToolPackageInstaller.StagingDirectory)
39+
{
40+
continue;
41+
}
42+
43+
yield return EnumerateVersions(packageId);
44+
}
45+
}
46+
47+
private IEnumerable<IToolPackage> EnumerateVersions(string packageId)
48+
{
2549
var packageRootDirectory = Root.WithSubDirectories(packageId);
2650
if (!Directory.Exists(packageRootDirectory.Value))
2751
{

src/dotnet/commands/dotnet-help/LocalizableStrings.resx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@
193193
<value>Remove reference from the project.</value>
194194
</data>
195195
<data name="ListDefinition" xml:space="preserve">
196-
<value>List reference in the project.</value>
196+
<value>List project references or installed tools.</value>
197197
</data>
198198
<data name="AdvancedCommands" xml:space="preserve">
199199
<value>Advanced Commands</value>

src/dotnet/commands/dotnet-help/xlf/LocalizableStrings.cs.xlf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@
153153
<note />
154154
</trans-unit>
155155
<trans-unit id="ListDefinition">
156-
<source>List reference in the project.</source>
157-
<target state="translated">Vypíše odkaz v projektu.</target>
156+
<source>List project references or installed tools.</source>
157+
<target state="needs-review-translation">Vypíše odkaz v projektu.</target>
158158
<note />
159159
</trans-unit>
160160
<trans-unit id="CommandDoesNotExist">

src/dotnet/commands/dotnet-help/xlf/LocalizableStrings.de.xlf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@
153153
<note />
154154
</trans-unit>
155155
<trans-unit id="ListDefinition">
156-
<source>List reference in the project.</source>
157-
<target state="translated">Verweis im Projekt auflisten.</target>
156+
<source>List project references or installed tools.</source>
157+
<target state="needs-review-translation">Verweis im Projekt auflisten.</target>
158158
<note />
159159
</trans-unit>
160160
<trans-unit id="CommandDoesNotExist">

src/dotnet/commands/dotnet-help/xlf/LocalizableStrings.es.xlf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@
153153
<note />
154154
</trans-unit>
155155
<trans-unit id="ListDefinition">
156-
<source>List reference in the project.</source>
157-
<target state="translated">Muestra referencias en el proyecto.</target>
156+
<source>List project references or installed tools.</source>
157+
<target state="needs-review-translation">Muestra referencias en el proyecto.</target>
158158
<note />
159159
</trans-unit>
160160
<trans-unit id="CommandDoesNotExist">

src/dotnet/commands/dotnet-help/xlf/LocalizableStrings.fr.xlf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@
153153
<note />
154154
</trans-unit>
155155
<trans-unit id="ListDefinition">
156-
<source>List reference in the project.</source>
157-
<target state="translated">Listez une référence dans le projet.</target>
156+
<source>List project references or installed tools.</source>
157+
<target state="needs-review-translation">Listez une référence dans le projet.</target>
158158
<note />
159159
</trans-unit>
160160
<trans-unit id="CommandDoesNotExist">

src/dotnet/commands/dotnet-help/xlf/LocalizableStrings.it.xlf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@
153153
<note />
154154
</trans-unit>
155155
<trans-unit id="ListDefinition">
156-
<source>List reference in the project.</source>
157-
<target state="translated">Elenca il riferimento nel progetto.</target>
156+
<source>List project references or installed tools.</source>
157+
<target state="needs-review-translation">Elenca il riferimento nel progetto.</target>
158158
<note />
159159
</trans-unit>
160160
<trans-unit id="CommandDoesNotExist">

0 commit comments

Comments
 (0)