chore: refactored test dummy program
All checks were successful
default / default (8.0) (push) Successful in 46s
All checks were successful
default / default (8.0) (push) Successful in 46s
Refactored the dummy program to always use async commands. Also added a Terminal abstractions to help the problem with char and byte interop when writing or reading data from the std pipes.
This commit is contained in:
parent
54185e7877
commit
7e67992a18
13 changed files with 159 additions and 51 deletions
|
@ -5,20 +5,21 @@ using Spectre.Console.Cli;
|
|||
|
||||
namespace Geekeey.Extensions.Process.Tests.Dummy.Commands;
|
||||
|
||||
internal sealed class GenerateClobCommand : Command<GenerateClobCommand.Settings>
|
||||
internal sealed class GenerateClobCommand : AsyncOutputCommand<GenerateClobCommand.Settings>
|
||||
{
|
||||
private readonly Random _random = new(1234567);
|
||||
private readonly char[] _chars = Enumerable.Range(32, 94).Select(i => (char)i).ToArray();
|
||||
|
||||
public sealed class Settings : CommandSettings
|
||||
public sealed class Settings : OutputCommandSettings
|
||||
{
|
||||
[CommandOption("--target")] public OutputTarget Target { get; init; } = OutputTarget.StdOut;
|
||||
[CommandOption("--length")] public int Length { get; init; } = 100_000;
|
||||
[CommandOption("--lines")] public int LinesCount { get; init; } = 1;
|
||||
}
|
||||
|
||||
public override int Execute(CommandContext context, Settings settings)
|
||||
public override async Task<int> ExecuteAsync(CommandContext context, Settings settings)
|
||||
{
|
||||
using var tty = Terminal.Connect();
|
||||
|
||||
var buffer = new StringBuilder(settings.Length);
|
||||
|
||||
for (var line = 0; line < settings.LinesCount; line++)
|
||||
|
@ -30,9 +31,9 @@ internal sealed class GenerateClobCommand : Command<GenerateClobCommand.Settings
|
|||
buffer.Append(_chars[_random.Next(0, _chars.Length)]);
|
||||
}
|
||||
|
||||
foreach (var writer in settings.Target.GetWriters())
|
||||
foreach (var writer in tty.GetWriters(settings.Target))
|
||||
{
|
||||
writer.WriteLine(buffer.ToString());
|
||||
await writer.WriteLineAsync(buffer.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue