feat: remove spectre.console
All checks were successful
default / dotnet-default-workflow (pull_request) Successful in 2m28s
default / dotnet-default-workflow (push) Successful in 1m16s

Replace `Spectre.Console.Cli` with `System.CommandLine`
This commit is contained in:
Louis Seubert 2026-05-10 15:08:55 +02:00
commit d5629a49a9
Signed by: louis9902
GPG key ID: 4B9DB28F826553BD
14 changed files with 150 additions and 134 deletions

View file

@ -2,21 +2,26 @@
// SPDX-License-Identifier: EUPL-1.2
using System.Buffers;
using System.CommandLine;
using System.Globalization;
using Spectre.Console.Cli;
internal sealed class LengthCommand : AsyncOutputCommand<LengthCommand.Settings>
internal sealed class LengthCommand : Command
{
public sealed class Settings : OutputCommandSettings
private static readonly Option<OutputTarget> Target = new("--target") { DefaultValueFactory = _ => OutputTarget.StdOut };
private static readonly Option<int> Buffer = new("--buffer") { DefaultValueFactory = _ => 81920 };
public LengthCommand() : base("length")
{
Add(Target);
Add(Buffer);
SetAction(ExecuteAsync);
}
public override async Task<int> ExecuteAsync(CommandContext context, Settings settings, CancellationToken cancellationToken)
public async Task<int> ExecuteAsync(ParseResult result, CancellationToken cancellationToken)
{
using var output = Output.Connect();
using var buffer = MemoryPool<byte>.Shared.Rent(81920);
using var buffer = MemoryPool<byte>.Shared.Rent(result.GetRequiredValue(Buffer));
var count = 0L;
while (true)
@ -30,7 +35,7 @@ internal sealed class LengthCommand : AsyncOutputCommand<LengthCommand.Settings>
count += bytesRead;
}
foreach (var writer in output.GetWriters(settings.Target))
foreach (var writer in output.GetWriters(result.GetRequiredValue(Target)))
{
await writer.WriteLineAsync(count.ToString(CultureInfo.InvariantCulture));
}