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

Commit 95c0359

Browse files
author
Peter Huene
committed
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.
1 parent d3244e8 commit 95c0359

21 files changed

+334
-91
lines changed

src/dotnet/commands/dotnet-list/dotnet-list-tool/ListToolCommand.cs

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,48 @@
1313

1414
namespace Microsoft.DotNet.Tools.List.Tool
1515
{
16+
internal delegate IToolPackageStore CreateToolPackageStore(DirectoryPath? nonGlobalLocation = null);
17+
1618
internal class ListToolCommand : CommandBase
1719
{
1820
public const string CommandDelimiter = ", ";
1921
private readonly AppliedOption _options;
20-
private readonly IToolPackageStore _toolPackageStore;
2122
private readonly IReporter _reporter;
2223
private readonly IReporter _errorReporter;
24+
private CreateToolPackageStore _createToolPackageStore;
2325

2426
public ListToolCommand(
2527
AppliedOption options,
2628
ParseResult result,
27-
IToolPackageStore toolPackageStore = null,
29+
CreateToolPackageStore createToolPackageStore = null,
2830
IReporter reporter = null)
2931
: base(result)
3032
{
3133
_options = options ?? throw new ArgumentNullException(nameof(options));
32-
_toolPackageStore = toolPackageStore ?? new ToolPackageStore(
33-
new DirectoryPath(new CliFolderPathCalculator().ToolsPackagePath));
3434
_reporter = reporter ?? Reporter.Output;
3535
_errorReporter = reporter ?? Reporter.Error;
36+
_createToolPackageStore = createToolPackageStore ?? ToolPackageFactory.CreateToolPackageStore;
3637
}
3738

3839
public override int Execute()
3940
{
40-
if (!_options.ValueOrDefault<bool>("global"))
41+
var global = _options.ValueOrDefault<bool>("global");
42+
var toolPathOption = _options.ValueOrDefault<string>("tool-path");
43+
44+
DirectoryPath? toolPath = null;
45+
if (!string.IsNullOrWhiteSpace(toolPathOption))
46+
{
47+
toolPath = new DirectoryPath(toolPathOption);
48+
}
49+
50+
if (toolPath == null && !global)
51+
{
52+
throw new GracefulException(LocalizableStrings.NeedGlobalOrToolPath);
53+
}
54+
55+
if (toolPath != null && global)
4156
{
42-
throw new GracefulException(LocalizableStrings.ListToolCommandOnlySupportsGlobal);
57+
throw new GracefulException(LocalizableStrings.GlobalAndToolPathConflict);
4358
}
4459

4560
var table = new PrintableTable<IToolPackage>();
@@ -54,13 +69,13 @@ public override int Execute()
5469
LocalizableStrings.CommandsColumn,
5570
p => string.Join(CommandDelimiter, p.Commands.Select(c => c.Name)));
5671

57-
table.PrintRows(GetPackages(), l => _reporter.WriteLine(l));
72+
table.PrintRows(GetPackages(toolPath), l => _reporter.WriteLine(l));
5873
return 0;
5974
}
6075

61-
private IEnumerable<IToolPackage> GetPackages()
76+
private IEnumerable<IToolPackage> GetPackages(DirectoryPath? toolPath)
6277
{
63-
return _toolPackageStore.EnumeratePackages()
78+
return _createToolPackageStore(toolPath).EnumeratePackages()
6479
.Where(PackageHasCommands)
6580
.OrderBy(p => p.Id)
6681
.ToArray();

src/dotnet/commands/dotnet-list/dotnet-list-tool/ListToolCommandParser.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ public static Command ListTool()
1717
"-g|--global",
1818
LocalizableStrings.GlobalOptionDescription,
1919
Accept.NoArguments()),
20+
Create.Option(
21+
"--tool-path",
22+
LocalizableStrings.ToolPathDescription,
23+
Accept.ExactlyOneArgument()),
2024
CommonOptions.HelpOption());
2125
}
2226
}

src/dotnet/commands/dotnet-list/dotnet-list-tool/LocalizableStrings.resx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,14 @@
123123
<data name="GlobalOptionDescription" xml:space="preserve">
124124
<value>List user wide tools.</value>
125125
</data>
126-
<data name="ListToolCommandOnlySupportsGlobal" xml:space="preserve">
127-
<value>The --global switch (-g) is currently required because only user wide tools are supported.</value>
126+
<data name="ToolPathDescription" xml:space="preserve">
127+
<value>Location where the tools are installed.</value>
128+
</data>
129+
<data name="NeedGlobalOrToolPath" xml:space="preserve">
130+
<value>Please specify either the global option (--global) or the tool path option (--tool-path).</value>
131+
</data>
132+
<data name="GlobalAndToolPathConflict" xml:space="preserve">
133+
<value>(--global) conflicts with the tool path option (--tool-path). Please specify only one of the options.</value>
128134
</data>
129135
<data name="InvalidPackageWarning" xml:space="preserve">
130136
<value>Warning: tool package '{0}' is invalid: {1}</value>

src/dotnet/commands/dotnet-list/dotnet-list-tool/xlf/LocalizableStrings.cs.xlf

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@
1212
<target state="new">List user wide tools.</target>
1313
<note />
1414
</trans-unit>
15-
<trans-unit id="ListToolCommandOnlySupportsGlobal">
16-
<source>The --global switch (-g) is currently required because only user wide tools are supported.</source>
17-
<target state="new">The --global switch (-g) is currently required because only user wide tools are supported.</target>
18-
<note />
19-
</trans-unit>
2015
<trans-unit id="VersionColumn">
2116
<source>Version</source>
2217
<target state="new">Version</target>
@@ -37,6 +32,21 @@
3732
<target state="new">Warning: tool package '{0}' is invalid: {1}</target>
3833
<note />
3934
</trans-unit>
35+
<trans-unit id="ToolPathDescription">
36+
<source>Location where the tools are installed.</source>
37+
<target state="new">Location where the tools are installed.</target>
38+
<note />
39+
</trans-unit>
40+
<trans-unit id="NeedGlobalOrToolPath">
41+
<source>Please specify either the global option (--global) or the tool path option (--tool-path).</source>
42+
<target state="new">Please specify either the global option (--global) or the tool path option (--tool-path).</target>
43+
<note />
44+
</trans-unit>
45+
<trans-unit id="GlobalAndToolPathConflict">
46+
<source>(--global) conflicts with the tool path option (--tool-path). Please specify only one of the options.</source>
47+
<target state="new">(--global) conflicts with the tool path option (--tool-path). Please specify only one of the options.</target>
48+
<note />
49+
</trans-unit>
4050
</body>
4151
</file>
4252
</xliff>

src/dotnet/commands/dotnet-list/dotnet-list-tool/xlf/LocalizableStrings.de.xlf

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@
1212
<target state="new">List user wide tools.</target>
1313
<note />
1414
</trans-unit>
15-
<trans-unit id="ListToolCommandOnlySupportsGlobal">
16-
<source>The --global switch (-g) is currently required because only user wide tools are supported.</source>
17-
<target state="new">The --global switch (-g) is currently required because only user wide tools are supported.</target>
18-
<note />
19-
</trans-unit>
2015
<trans-unit id="VersionColumn">
2116
<source>Version</source>
2217
<target state="new">Version</target>
@@ -37,6 +32,21 @@
3732
<target state="new">Warning: tool package '{0}' is invalid: {1}</target>
3833
<note />
3934
</trans-unit>
35+
<trans-unit id="ToolPathDescription">
36+
<source>Location where the tools are installed.</source>
37+
<target state="new">Location where the tools are installed.</target>
38+
<note />
39+
</trans-unit>
40+
<trans-unit id="NeedGlobalOrToolPath">
41+
<source>Please specify either the global option (--global) or the tool path option (--tool-path).</source>
42+
<target state="new">Please specify either the global option (--global) or the tool path option (--tool-path).</target>
43+
<note />
44+
</trans-unit>
45+
<trans-unit id="GlobalAndToolPathConflict">
46+
<source>(--global) conflicts with the tool path option (--tool-path). Please specify only one of the options.</source>
47+
<target state="new">(--global) conflicts with the tool path option (--tool-path). Please specify only one of the options.</target>
48+
<note />
49+
</trans-unit>
4050
</body>
4151
</file>
4252
</xliff>

src/dotnet/commands/dotnet-list/dotnet-list-tool/xlf/LocalizableStrings.es.xlf

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@
1212
<target state="new">List user wide tools.</target>
1313
<note />
1414
</trans-unit>
15-
<trans-unit id="ListToolCommandOnlySupportsGlobal">
16-
<source>The --global switch (-g) is currently required because only user wide tools are supported.</source>
17-
<target state="new">The --global switch (-g) is currently required because only user wide tools are supported.</target>
18-
<note />
19-
</trans-unit>
2015
<trans-unit id="VersionColumn">
2116
<source>Version</source>
2217
<target state="new">Version</target>
@@ -37,6 +32,21 @@
3732
<target state="new">Warning: tool package '{0}' is invalid: {1}</target>
3833
<note />
3934
</trans-unit>
35+
<trans-unit id="ToolPathDescription">
36+
<source>Location where the tools are installed.</source>
37+
<target state="new">Location where the tools are installed.</target>
38+
<note />
39+
</trans-unit>
40+
<trans-unit id="NeedGlobalOrToolPath">
41+
<source>Please specify either the global option (--global) or the tool path option (--tool-path).</source>
42+
<target state="new">Please specify either the global option (--global) or the tool path option (--tool-path).</target>
43+
<note />
44+
</trans-unit>
45+
<trans-unit id="GlobalAndToolPathConflict">
46+
<source>(--global) conflicts with the tool path option (--tool-path). Please specify only one of the options.</source>
47+
<target state="new">(--global) conflicts with the tool path option (--tool-path). Please specify only one of the options.</target>
48+
<note />
49+
</trans-unit>
4050
</body>
4151
</file>
4252
</xliff>

src/dotnet/commands/dotnet-list/dotnet-list-tool/xlf/LocalizableStrings.fr.xlf

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@
1212
<target state="new">List user wide tools.</target>
1313
<note />
1414
</trans-unit>
15-
<trans-unit id="ListToolCommandOnlySupportsGlobal">
16-
<source>The --global switch (-g) is currently required because only user wide tools are supported.</source>
17-
<target state="new">The --global switch (-g) is currently required because only user wide tools are supported.</target>
18-
<note />
19-
</trans-unit>
2015
<trans-unit id="VersionColumn">
2116
<source>Version</source>
2217
<target state="new">Version</target>
@@ -37,6 +32,21 @@
3732
<target state="new">Warning: tool package '{0}' is invalid: {1}</target>
3833
<note />
3934
</trans-unit>
35+
<trans-unit id="ToolPathDescription">
36+
<source>Location where the tools are installed.</source>
37+
<target state="new">Location where the tools are installed.</target>
38+
<note />
39+
</trans-unit>
40+
<trans-unit id="NeedGlobalOrToolPath">
41+
<source>Please specify either the global option (--global) or the tool path option (--tool-path).</source>
42+
<target state="new">Please specify either the global option (--global) or the tool path option (--tool-path).</target>
43+
<note />
44+
</trans-unit>
45+
<trans-unit id="GlobalAndToolPathConflict">
46+
<source>(--global) conflicts with the tool path option (--tool-path). Please specify only one of the options.</source>
47+
<target state="new">(--global) conflicts with the tool path option (--tool-path). Please specify only one of the options.</target>
48+
<note />
49+
</trans-unit>
4050
</body>
4151
</file>
4252
</xliff>

src/dotnet/commands/dotnet-list/dotnet-list-tool/xlf/LocalizableStrings.it.xlf

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@
1212
<target state="new">List user wide tools.</target>
1313
<note />
1414
</trans-unit>
15-
<trans-unit id="ListToolCommandOnlySupportsGlobal">
16-
<source>The --global switch (-g) is currently required because only user wide tools are supported.</source>
17-
<target state="new">The --global switch (-g) is currently required because only user wide tools are supported.</target>
18-
<note />
19-
</trans-unit>
2015
<trans-unit id="VersionColumn">
2116
<source>Version</source>
2217
<target state="new">Version</target>
@@ -37,6 +32,21 @@
3732
<target state="new">Warning: tool package '{0}' is invalid: {1}</target>
3833
<note />
3934
</trans-unit>
35+
<trans-unit id="ToolPathDescription">
36+
<source>Location where the tools are installed.</source>
37+
<target state="new">Location where the tools are installed.</target>
38+
<note />
39+
</trans-unit>
40+
<trans-unit id="NeedGlobalOrToolPath">
41+
<source>Please specify either the global option (--global) or the tool path option (--tool-path).</source>
42+
<target state="new">Please specify either the global option (--global) or the tool path option (--tool-path).</target>
43+
<note />
44+
</trans-unit>
45+
<trans-unit id="GlobalAndToolPathConflict">
46+
<source>(--global) conflicts with the tool path option (--tool-path). Please specify only one of the options.</source>
47+
<target state="new">(--global) conflicts with the tool path option (--tool-path). Please specify only one of the options.</target>
48+
<note />
49+
</trans-unit>
4050
</body>
4151
</file>
4252
</xliff>

src/dotnet/commands/dotnet-list/dotnet-list-tool/xlf/LocalizableStrings.ja.xlf

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@
1212
<target state="new">List user wide tools.</target>
1313
<note />
1414
</trans-unit>
15-
<trans-unit id="ListToolCommandOnlySupportsGlobal">
16-
<source>The --global switch (-g) is currently required because only user wide tools are supported.</source>
17-
<target state="new">The --global switch (-g) is currently required because only user wide tools are supported.</target>
18-
<note />
19-
</trans-unit>
2015
<trans-unit id="VersionColumn">
2116
<source>Version</source>
2217
<target state="new">Version</target>
@@ -37,6 +32,21 @@
3732
<target state="new">Warning: tool package '{0}' is invalid: {1}</target>
3833
<note />
3934
</trans-unit>
35+
<trans-unit id="ToolPathDescription">
36+
<source>Location where the tools are installed.</source>
37+
<target state="new">Location where the tools are installed.</target>
38+
<note />
39+
</trans-unit>
40+
<trans-unit id="NeedGlobalOrToolPath">
41+
<source>Please specify either the global option (--global) or the tool path option (--tool-path).</source>
42+
<target state="new">Please specify either the global option (--global) or the tool path option (--tool-path).</target>
43+
<note />
44+
</trans-unit>
45+
<trans-unit id="GlobalAndToolPathConflict">
46+
<source>(--global) conflicts with the tool path option (--tool-path). Please specify only one of the options.</source>
47+
<target state="new">(--global) conflicts with the tool path option (--tool-path). Please specify only one of the options.</target>
48+
<note />
49+
</trans-unit>
4050
</body>
4151
</file>
4252
</xliff>

src/dotnet/commands/dotnet-list/dotnet-list-tool/xlf/LocalizableStrings.ko.xlf

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@
1212
<target state="new">List user wide tools.</target>
1313
<note />
1414
</trans-unit>
15-
<trans-unit id="ListToolCommandOnlySupportsGlobal">
16-
<source>The --global switch (-g) is currently required because only user wide tools are supported.</source>
17-
<target state="new">The --global switch (-g) is currently required because only user wide tools are supported.</target>
18-
<note />
19-
</trans-unit>
2015
<trans-unit id="VersionColumn">
2116
<source>Version</source>
2217
<target state="new">Version</target>
@@ -37,6 +32,21 @@
3732
<target state="new">Warning: tool package '{0}' is invalid: {1}</target>
3833
<note />
3934
</trans-unit>
35+
<trans-unit id="ToolPathDescription">
36+
<source>Location where the tools are installed.</source>
37+
<target state="new">Location where the tools are installed.</target>
38+
<note />
39+
</trans-unit>
40+
<trans-unit id="NeedGlobalOrToolPath">
41+
<source>Please specify either the global option (--global) or the tool path option (--tool-path).</source>
42+
<target state="new">Please specify either the global option (--global) or the tool path option (--tool-path).</target>
43+
<note />
44+
</trans-unit>
45+
<trans-unit id="GlobalAndToolPathConflict">
46+
<source>(--global) conflicts with the tool path option (--tool-path). Please specify only one of the options.</source>
47+
<target state="new">(--global) conflicts with the tool path option (--tool-path). Please specify only one of the options.</target>
48+
<note />
49+
</trans-unit>
4050
</body>
4151
</file>
4252
</xliff>

0 commit comments

Comments
 (0)