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

Commit

Permalink
Add list for local tools
Browse files Browse the repository at this point in the history
  • Loading branch information
William Li committed Dec 4, 2018
1 parent 9ed8cf2 commit 2f260f7
Show file tree
Hide file tree
Showing 23 changed files with 306 additions and 123 deletions.
14 changes: 14 additions & 0 deletions src/dotnet/ToolManifest/IToolManifestInspector.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Collections.Generic;
using Microsoft.Extensions.EnvironmentAbstractions;

namespace Microsoft.DotNet.ToolManifest
{
internal interface IToolManifestInspector
{
IReadOnlyCollection<(ToolManifestPackage toolManifestPackage, FilePath SourceManifest)> Inspect(
FilePath? filePath = null);
}
}
15 changes: 14 additions & 1 deletion src/dotnet/ToolManifest/ToolManifestFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace Microsoft.DotNet.ToolManifest
{
internal class ToolManifestFinder : IToolManifestFinder
internal class ToolManifestFinder : IToolManifestFinder, IToolManifestInspector
{
private readonly DirectoryPath _probeStart;
private readonly IFileSystem _fileSystem;
Expand Down Expand Up @@ -48,6 +48,19 @@ public IReadOnlyCollection<ToolManifestPackage> Find(FilePath? filePath = null)
return toolManifestPackageAndSource.Select(t => t.toolManifestPackage).ToArray();
}

public IReadOnlyCollection<(ToolManifestPackage toolManifestPackage, FilePath SourceManifest)> Inspect(
FilePath? filePath = null)
{
IEnumerable<(FilePath manifestfile, DirectoryPath _)> allPossibleManifests =
filePath != null
? new[] {(filePath.Value, filePath.Value.GetDirectoryPath())}
: EnumerateDefaultAllPossibleManifests();

TryFindToolManifestPackages(allPossibleManifests, out var toolManifestPackageAndSource);

return toolManifestPackageAndSource.ToArray();
}

private bool TryFindToolManifestPackages(
IEnumerable<(FilePath manifestfile, DirectoryPath _)> allPossibleManifests,
out List<(ToolManifestPackage toolManifestPackage, FilePath SourceManifest)> toolManifestPackageAndSource)
Expand Down
115 changes: 0 additions & 115 deletions src/dotnet/commands/dotnet-tool/list/LocalizableStrings.Designer.cs

This file was deleted.

3 changes: 3 additions & 0 deletions src/dotnet/commands/dotnet-tool/list/LocalizableStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@
<data name="CommandsColumn" xml:space="preserve">
<value>Commands</value>
</data>
<data name="ManifestFileColumn" xml:space="preserve">
<value>Manifest</value>
</data>
<data name="InvalidToolPathOption" xml:space="preserve">
<value>Tool path '{0}' does not exist.</value>
</data>
Expand Down
15 changes: 13 additions & 2 deletions src/dotnet/commands/dotnet-tool/list/ToolListCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ internal class ToolListCommand : CommandBase
private readonly AppliedOption _options;
private readonly ParseResult _result;
private readonly ToolListGlobalOrToolPathCommand _toolListGlobalOrToolPathCommand;
private readonly ToolListLocalCommand _toolListLocalCommand;
private readonly bool _global;
private readonly bool _local;
private readonly string _toolPath;
Expand All @@ -29,14 +30,17 @@ internal class ToolListCommand : CommandBase
public ToolListCommand(
AppliedOption options,
ParseResult result,
ToolListGlobalOrToolPathCommand toolListGlobalOrToolPathCommand = null
ToolListGlobalOrToolPathCommand toolListGlobalOrToolPathCommand = null,
ToolListLocalCommand toolListLocalCommand = null
)
: base(result)
{
_options = options ?? throw new ArgumentNullException(nameof(options));
_result = result ?? throw new ArgumentNullException(nameof(result));
_toolListGlobalOrToolPathCommand
= toolListGlobalOrToolPathCommand ?? new ToolListGlobalOrToolPathCommand(_options, _result);
_toolListLocalCommand
= toolListLocalCommand ?? new ToolListLocalCommand(_options, _result);
_global = options.ValueOrDefault<bool>(GlobalOption);
_local = options.ValueOrDefault<bool>(LocalOption);
_toolPath = options.SingleArgumentOrDefault(ToolPathOption);
Expand All @@ -46,7 +50,14 @@ public override int Execute()
{
EnsureNoConflictGlobalLocalToolPathOption();

return _toolListGlobalOrToolPathCommand.Execute();
if (_global || !string.IsNullOrWhiteSpace(_toolPath))
{
return _toolListGlobalOrToolPathCommand.Execute();
}
else
{
return _toolListLocalCommand.Execute();
}
}

private void EnsureNoConflictGlobalLocalToolPathOption()
Expand Down
60 changes: 60 additions & 0 deletions src/dotnet/commands/dotnet-tool/list/ToolListLocalCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.IO;
using System.Linq;
using Microsoft.DotNet.Cli;
using Microsoft.DotNet.Cli.CommandLine;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.ToolManifest;
using Microsoft.Extensions.EnvironmentAbstractions;

namespace Microsoft.DotNet.Tools.Tool.List
{
internal class ToolListLocalCommand : CommandBase
{
private readonly IToolManifestInspector _toolManifestInspector;
private readonly IReporter _reporter;
private const string CommandDelimiter = ", ";

public ToolListLocalCommand(
AppliedOption appliedCommand,
ParseResult parseResult,
IToolManifestInspector toolManifestInspector = null,
IReporter reporter = null)
: base(parseResult)
{
if (appliedCommand == null)
{
throw new ArgumentNullException(nameof(appliedCommand));
}

_reporter = (reporter ?? Reporter.Output);

_toolManifestInspector = toolManifestInspector ??
new ToolManifestFinder(new DirectoryPath(Directory.GetCurrentDirectory()));
}

public override int Execute()
{
var table = new PrintableTable<(ToolManifestPackage toolManifestPackage, FilePath SourceManifest)>();

table.AddColumn(
LocalizableStrings.PackageIdColumn,
p => p.toolManifestPackage.PackageId.ToString());
table.AddColumn(
LocalizableStrings.VersionColumn,
p => p.toolManifestPackage.Version.ToNormalizedString());
table.AddColumn(
LocalizableStrings.CommandsColumn,
p => string.Join(CommandDelimiter, p.toolManifestPackage.CommandNames.Select(c => c.Value)));
table.AddColumn(
LocalizableStrings.ManifestFileColumn,
p => p.SourceManifest.Value);

table.PrintRows(_toolManifestInspector.Inspect(), l => _reporter.WriteLine(l));
return 0;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
<target state="new">List the tools installed in the local tool manifest.</target>
<note />
</trans-unit>
<trans-unit id="ManifestFileColumn">
<source>Manifest</source>
<target state="new">Manifest</target>
<note />
</trans-unit>
<trans-unit id="VersionColumn">
<source>Version</source>
<target state="translated">Verze</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
<target state="new">List the tools installed in the local tool manifest.</target>
<note />
</trans-unit>
<trans-unit id="ManifestFileColumn">
<source>Manifest</source>
<target state="new">Manifest</target>
<note />
</trans-unit>
<trans-unit id="VersionColumn">
<source>Version</source>
<target state="translated">Version</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
<target state="new">List the tools installed in the local tool manifest.</target>
<note />
</trans-unit>
<trans-unit id="ManifestFileColumn">
<source>Manifest</source>
<target state="new">Manifest</target>
<note />
</trans-unit>
<trans-unit id="VersionColumn">
<source>Version</source>
<target state="translated">Versión</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
<target state="new">List the tools installed in the local tool manifest.</target>
<note />
</trans-unit>
<trans-unit id="ManifestFileColumn">
<source>Manifest</source>
<target state="new">Manifest</target>
<note />
</trans-unit>
<trans-unit id="VersionColumn">
<source>Version</source>
<target state="translated">Version</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
<target state="new">List the tools installed in the local tool manifest.</target>
<note />
</trans-unit>
<trans-unit id="ManifestFileColumn">
<source>Manifest</source>
<target state="new">Manifest</target>
<note />
</trans-unit>
<trans-unit id="VersionColumn">
<source>Version</source>
<target state="translated">Versione</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
<target state="new">List the tools installed in the local tool manifest.</target>
<note />
</trans-unit>
<trans-unit id="ManifestFileColumn">
<source>Manifest</source>
<target state="new">Manifest</target>
<note />
</trans-unit>
<trans-unit id="VersionColumn">
<source>Version</source>
<target state="translated">バージョン</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
<target state="new">List the tools installed in the local tool manifest.</target>
<note />
</trans-unit>
<trans-unit id="ManifestFileColumn">
<source>Manifest</source>
<target state="new">Manifest</target>
<note />
</trans-unit>
<trans-unit id="VersionColumn">
<source>Version</source>
<target state="translated">버전</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
<target state="new">List the tools installed in the local tool manifest.</target>
<note />
</trans-unit>
<trans-unit id="ManifestFileColumn">
<source>Manifest</source>
<target state="new">Manifest</target>
<note />
</trans-unit>
<trans-unit id="VersionColumn">
<source>Version</source>
<target state="translated">Wersja</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
<target state="new">List the tools installed in the local tool manifest.</target>
<note />
</trans-unit>
<trans-unit id="ManifestFileColumn">
<source>Manifest</source>
<target state="new">Manifest</target>
<note />
</trans-unit>
<trans-unit id="VersionColumn">
<source>Version</source>
<target state="translated">Versão</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
<target state="new">List the tools installed in the local tool manifest.</target>
<note />
</trans-unit>
<trans-unit id="ManifestFileColumn">
<source>Manifest</source>
<target state="new">Manifest</target>
<note />
</trans-unit>
<trans-unit id="VersionColumn">
<source>Version</source>
<target state="translated">Версия</target>
Expand Down
Loading

0 comments on commit 2f260f7

Please sign in to comment.