feat: remove spectre.console
Replace `Spectre.Console.Cli` with `System.CommandLine`
This commit is contained in:
parent
48c483c568
commit
d5629a49a9
14 changed files with 150 additions and 134 deletions
|
|
@ -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));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue