Skip to content

Commit 6a89e20

Browse files
committed
Add list command
1 parent c623aa7 commit 6a89e20

File tree

6 files changed

+195
-2
lines changed

6 files changed

+195
-2
lines changed

src/dotnet-bootstrapper/BootstrapperCommandParser.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.CommandLine.Parsing;
99
using System.Reflection;
1010
using Microsoft.DotNet.Tools.Uninstall.Shared.Configs;
11+
using Microsoft.DotNet.Tools.Bootstrapper.Commands.List;
1112

1213
namespace Microsoft.DotNet.Tools.Bootstrapper
1314
{
@@ -21,7 +22,7 @@ internal static class BootstrapperCommandParser
2122
static BootstrapperCommandParser()
2223
{
2324
BootstrapperRootCommand.AddCommand(CommandLineConfigs.VersionSubcommand);
24-
BootstrapperRootCommand.AddCommand(CommandLineConfigs.ListCommand);
25+
BootstrapperRootCommand.AddCommand(ListCommandParser.GetCommand());
2526
BootstrapperRootCommand.AddCommand(CommandLineConfigs.RemoveCommand);
2627
BootstrapperRootCommand.AddCommand(HelpCommand);
2728
HelpCommand.Handler = CommandHandler.Create(() =>
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.CommandLine.Parsing;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace Microsoft.DotNet.Tools.Bootstrapper
9+
{
10+
public abstract class CommandBase
11+
{
12+
protected ParseResult _parseResult;
13+
14+
protected CommandBase(ParseResult parseResult)
15+
{
16+
_parseResult = parseResult;
17+
}
18+
19+
public abstract int Execute();
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.CommandLine.Parsing;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using Microsoft.Deployment.DotNet.Releases;
8+
using Spectre.Console;
9+
10+
namespace Microsoft.DotNet.Tools.Bootstrapper.Commands.List
11+
{
12+
internal class ListCommand(
13+
ParseResult parseResult) : CommandBase(parseResult)
14+
{
15+
private string _channel = parseResult.ValueForArgument(ListCommandParser.ChannelArgument);
16+
private bool _allowPreviews = parseResult.ValueForOption(ListCommandParser.AllowPreviews);
17+
public override int Execute()
18+
{
19+
List<Product> productCollection = [.. ProductCollection.GetAsync().Result];
20+
productCollection = [..
21+
productCollection.Where(product => !product.IsOutOfSupport() && (product.SupportPhase != SupportPhase.Preview || _allowPreviews))];
22+
23+
if (!string.IsNullOrEmpty(_channel))
24+
{
25+
productCollection = [.. productCollection.Where(product => product.ProductVersion.Equals(_channel, StringComparison.OrdinalIgnoreCase))];
26+
}
27+
28+
foreach (Product product in productCollection)
29+
{
30+
string productHeader = $"{product.ProductName} {product.ProductVersion}";
31+
Console.WriteLine(productHeader);
32+
33+
Table productMetadataTable = new Table()
34+
.Expand()
35+
.AddColumn("Version")
36+
.AddColumn("Release Date")
37+
.AddColumn("SDK")
38+
.AddColumn("Runtime")
39+
.AddColumn("ASP.NET Runtime")
40+
.AddColumn("Windows Desktop Runtime");
41+
42+
List<ProductRelease> releases = product.GetReleasesAsync().Result.ToList()
43+
.Where(relase => !relase.IsPreview || _allowPreviews).ToList();
44+
45+
foreach (ProductRelease release in releases)
46+
{
47+
productMetadataTable.AddRow(
48+
release.Version.ToString(),
49+
release.ReleaseDate.ToString("yyyy-MM-dd"),
50+
release.Sdks.FirstOrDefault()?.DisplayVersion ?? "N/A",
51+
release.Runtime?.DisplayVersion ?? "N/A",
52+
release.AspNetCoreRuntime?.DisplayVersion ?? "N/A",
53+
release.WindowsDesktopRuntime?.DisplayVersion ?? "N/A");
54+
}
55+
AnsiConsole.Write(productMetadataTable);
56+
Console.WriteLine();
57+
}
58+
59+
return 0;
60+
}
61+
}
62+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.CommandLine;
2+
using System.CommandLine.Invocation;
3+
using System.CommandLine.Parsing;
4+
5+
namespace Microsoft.DotNet.Tools.Bootstrapper.Commands.List
6+
{
7+
internal class ListCommandParser
8+
{
9+
internal static Argument<string> ChannelArgument = new Argument<string>(
10+
name: "channel",
11+
description: "The channel to list sdks for. If not specified, all sdks will be listed.")
12+
{
13+
Arity = ArgumentArity.ZeroOrOne
14+
};
15+
16+
internal static Option<bool> AllowPreviews = new Option<bool>(
17+
"--allow-previews",
18+
description: "Allow preview releases to be listed.");
19+
20+
private static readonly Command Command = ConstructCommand();
21+
public static Command GetCommand() => Command;
22+
private static Command ConstructCommand()
23+
{
24+
Command command = new("list", "List all sdks available for installation");
25+
command.AddArgument(ChannelArgument);
26+
command.AddOption(AllowPreviews);
27+
28+
command.Handler = CommandHandler.Create((ParseResult parseResult) =>
29+
{
30+
return new ListCommand(parseResult).Execute();
31+
});
32+
33+
return command;
34+
}
35+
}
36+
}

src/dotnet-bootstrapper/LocalizableStrings.Designer.cs

+72
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/dotnet-bootstrapper/dotnet-bootstrapper.csproj

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<PackageReference Include="System.CommandLine" Version="2.0.0-beta1.20574.7" />
2727
<PackageReference Include="System.CommandLine.Rendering" Version="0.3.0-alpha.20574.7" />
2828
<PackageReference Include="System.Resources.Extensions" Version="8.0.0" />
29-
<ProjectReference Include="..\dotnet-core-uninstall\dotnet-core-uninstall.csproj"/>
29+
<ProjectReference Include="..\dotnet-core-uninstall\dotnet-core-uninstall.csproj" />
3030
<PackageReference Include="Microsoft.Deployment.DotNet.Releases" Version="1.0.1" />
3131
</ItemGroup>
3232

@@ -42,6 +42,7 @@
4242
<EmbeddedResource Update="LocalizableStrings.resx">
4343
<Generator>ResXFileCodeGenerator</Generator>
4444
<LastGenOutput>LocalizableStrings.Designer.cs</LastGenOutput>
45+
<CustomToolNamespace>Microsoft.DotNet.Tools.Bootstrapper</CustomToolNamespace>
4546
</EmbeddedResource>
4647
</ItemGroup>
4748

0 commit comments

Comments
 (0)