Skip to content
This repository was archived by the owner on Apr 20, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/dotnet/ToolPackage/ToolPackageStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal class ToolPackageStore : IToolPackageStore

public ToolPackageStore(DirectoryPath root)
{
Root = root;
Root = new DirectoryPath(Path.GetFullPath(root.Value));
}

public DirectoryPath Root { get; private set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,48 @@

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))
{
toolPath = new DirectoryPath(toolPathOption);
}

if (toolPath == null && !global)
{
throw new GracefulException(LocalizableStrings.NeedGlobalOrToolPath);
}

if (toolPath != null && global)
{
throw new GracefulException(LocalizableStrings.ListToolCommandOnlySupportsGlobal);
throw new GracefulException(LocalizableStrings.GlobalAndToolPathConflict);
}

var table = new PrintableTable<IToolPackage>();
Expand All @@ -54,13 +69,13 @@ public override int Execute()
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ public static Command ListTool()
"-g|--global",
LocalizableStrings.GlobalOptionDescription,
Accept.NoArguments()),
Create.Option(
"--tool-path",
LocalizableStrings.ToolPathDescription,
Accept.ExactlyOneArgument()),
CommonOptions.HelpOption());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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>
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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>
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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>
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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>
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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>
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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>
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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>
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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>
Loading