40 lines
894 B
C#
40 lines
894 B
C#
|
|
// Copyright (c) The Geekeey Authors
|
||
|
|
// SPDX-License-Identifier: EUPL-1.2
|
||
|
|
|
||
|
|
using System.Buffers;
|
||
|
|
using System.Globalization;
|
||
|
|
|
||
|
|
using Spectre.Console.Cli;
|
||
|
|
|
||
|
|
internal sealed class LengthCommand : AsyncOutputCommand<LengthCommand.Settings>
|
||
|
|
{
|
||
|
|
public sealed class Settings : OutputCommandSettings
|
||
|
|
{
|
||
|
|
}
|
||
|
|
|
||
|
|
public override async Task<int> ExecuteAsync(CommandContext context, Settings settings, CancellationToken cancellationToken)
|
||
|
|
{
|
||
|
|
using var output = Output.Connect();
|
||
|
|
|
||
|
|
using var buffer = MemoryPool<byte>.Shared.Rent(81920);
|
||
|
|
|
||
|
|
var count = 0L;
|
||
|
|
while (true)
|
||
|
|
{
|
||
|
|
var bytesRead = await output.Stdin.BaseStream.ReadAsync(buffer.Memory, cancellationToken);
|
||
|
|
if (bytesRead <= 0)
|
||
|
|
{
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
|
||
|
|
count += bytesRead;
|
||
|
|
}
|
||
|
|
|
||
|
|
foreach (var writer in output.GetWriters(settings.Target))
|
||
|
|
{
|
||
|
|
await writer.WriteLineAsync(count.ToString(CultureInfo.InvariantCulture));
|
||
|
|
}
|
||
|
|
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
}
|