build: initial project release
Some checks failed
default / dotnet-default-workflow (push) Failing after 54s
Some checks failed
default / dotnet-default-workflow (push) Failing after 54s
This commit is contained in:
commit
1e4687aff6
59 changed files with 4902 additions and 0 deletions
25
src/process.dummy.app/_commands/EchoCommand.cs
Normal file
25
src/process.dummy.app/_commands/EchoCommand.cs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
// Copyright (c) The Geekeey Authors
|
||||
// SPDX-License-Identifier: EUPL-1.2
|
||||
|
||||
using Spectre.Console.Cli;
|
||||
|
||||
internal sealed class EchoCommand : AsyncOutputCommand<EchoCommand.Settings>
|
||||
{
|
||||
public sealed class Settings : OutputCommandSettings
|
||||
{
|
||||
[CommandOption("--separator <char>")] public string Separator { get; init; } = " ";
|
||||
[CommandArgument(0, "[line]")] public string[] Items { get; init; } = [];
|
||||
}
|
||||
|
||||
public override async Task<int> ExecuteAsync(CommandContext context, Settings settings, CancellationToken cancellationToken)
|
||||
{
|
||||
using var output = Output.Connect();
|
||||
|
||||
foreach (var writer in output.GetWriters(settings.Target))
|
||||
{
|
||||
await writer.WriteLineAsync(string.Join(settings.Separator, settings.Items));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
41
src/process.dummy.app/_commands/EchoStdinCommand.cs
Normal file
41
src/process.dummy.app/_commands/EchoStdinCommand.cs
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
// Copyright (c) The Geekeey Authors
|
||||
// SPDX-License-Identifier: EUPL-1.2
|
||||
|
||||
using System.Buffers;
|
||||
|
||||
using Spectre.Console.Cli;
|
||||
|
||||
internal sealed class EchoStdinCommand : AsyncOutputCommand<EchoStdinCommand.Settings>
|
||||
{
|
||||
public sealed class Settings : OutputCommandSettings
|
||||
{
|
||||
[CommandOption("--length")] public long Length { get; init; } = long.MaxValue;
|
||||
}
|
||||
|
||||
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 (count < settings.Length)
|
||||
{
|
||||
var bytesWanted = (int)Math.Min(buffer.Memory.Length, settings.Length - count);
|
||||
|
||||
var bytesRead = await output.Stdin.BaseStream.ReadAsync(buffer.Memory[..bytesWanted], cancellationToken);
|
||||
if (bytesRead <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
foreach (var writer in output.GetWriters(settings.Target))
|
||||
{
|
||||
await writer.BaseStream.WriteAsync(buffer.Memory[..bytesRead], cancellationToken);
|
||||
}
|
||||
|
||||
count += bytesRead;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
29
src/process.dummy.app/_commands/EnvironmentCommand.cs
Normal file
29
src/process.dummy.app/_commands/EnvironmentCommand.cs
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
// Copyright (c) The Geekeey Authors
|
||||
// SPDX-License-Identifier: EUPL-1.2
|
||||
|
||||
using Spectre.Console.Cli;
|
||||
|
||||
internal sealed class EnvironmentCommand : AsyncOutputCommand<EnvironmentCommand.Settings>
|
||||
{
|
||||
public sealed class Settings : OutputCommandSettings
|
||||
{
|
||||
[CommandArgument(0, "<ARGUMENT>")] public string[] Variables { get; init; } = [];
|
||||
}
|
||||
|
||||
public override async Task<int> ExecuteAsync(CommandContext context, Settings settings, CancellationToken cancellationToken)
|
||||
{
|
||||
using var output = Output.Connect();
|
||||
|
||||
foreach (var name in settings.Variables)
|
||||
{
|
||||
var value = Environment.GetEnvironmentVariable(name) ?? string.Empty;
|
||||
|
||||
foreach (var writer in output.GetWriters(settings.Target))
|
||||
{
|
||||
await writer.WriteLineAsync(value);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
21
src/process.dummy.app/_commands/ExitCommand.cs
Normal file
21
src/process.dummy.app/_commands/ExitCommand.cs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
// Copyright (c) The Geekeey Authors
|
||||
// SPDX-License-Identifier: EUPL-1.2
|
||||
|
||||
using Spectre.Console.Cli;
|
||||
|
||||
internal sealed class ExitCommand : AsyncCommand<ExitCommand.Settings>
|
||||
{
|
||||
public sealed class Settings : CommandSettings
|
||||
{
|
||||
[CommandArgument(1, "<code>")] public int Code { get; init; }
|
||||
}
|
||||
|
||||
public override async Task<int> ExecuteAsync(CommandContext context, Settings settings, CancellationToken cancellationToken)
|
||||
{
|
||||
using var output = Output.Connect();
|
||||
|
||||
await output.Stderr.WriteLineAsync($"Exit code set to {settings.Code}");
|
||||
|
||||
return settings.Code;
|
||||
}
|
||||
}
|
||||
40
src/process.dummy.app/_commands/GenerateBlobCommand.cs
Normal file
40
src/process.dummy.app/_commands/GenerateBlobCommand.cs
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
// Copyright (c) The Geekeey Authors
|
||||
// SPDX-License-Identifier: EUPL-1.2
|
||||
|
||||
using System.Buffers;
|
||||
|
||||
using Spectre.Console.Cli;
|
||||
|
||||
internal sealed class GenerateBlobCommand : AsyncOutputCommand<GenerateBlobCommand.Settings>
|
||||
{
|
||||
private readonly Random _random = new(1234567);
|
||||
|
||||
public sealed class Settings : OutputCommandSettings
|
||||
{
|
||||
[CommandOption("--length")] public long Length { get; init; } = 100_000;
|
||||
[CommandOption("--buffer")] public int BufferSize { get; init; } = 1024;
|
||||
}
|
||||
|
||||
public override async Task<int> ExecuteAsync(CommandContext context, Settings settings, CancellationToken cancellationToken)
|
||||
{
|
||||
using var output = Output.Connect();
|
||||
|
||||
using var bytes = MemoryPool<byte>.Shared.Rent(settings.BufferSize);
|
||||
|
||||
var total = 0L;
|
||||
while (total < settings.Length)
|
||||
{
|
||||
_random.NextBytes(bytes.Memory.Span);
|
||||
|
||||
var count = (int)Math.Min(bytes.Memory.Length, settings.Length - total);
|
||||
foreach (var writer in output.GetWriters(settings.Target))
|
||||
{
|
||||
await writer.BaseStream.WriteAsync(bytes.Memory[..count], cancellationToken);
|
||||
}
|
||||
|
||||
total += count;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
42
src/process.dummy.app/_commands/GenerateClobCommand.cs
Normal file
42
src/process.dummy.app/_commands/GenerateClobCommand.cs
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
// Copyright (c) The Geekeey Authors
|
||||
// SPDX-License-Identifier: EUPL-1.2
|
||||
|
||||
using System.Text;
|
||||
|
||||
using Spectre.Console.Cli;
|
||||
|
||||
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)];
|
||||
|
||||
public sealed class Settings : OutputCommandSettings
|
||||
{
|
||||
[CommandOption("--length")] public int Length { get; init; } = 100_000;
|
||||
[CommandOption("--lines")] public int LinesCount { get; init; } = 1;
|
||||
}
|
||||
|
||||
public override async Task<int> ExecuteAsync(CommandContext context, Settings settings, CancellationToken cancellationToken)
|
||||
{
|
||||
using var output = Output.Connect();
|
||||
|
||||
var buffer = new StringBuilder(settings.Length);
|
||||
|
||||
for (var line = 0; line < settings.LinesCount; line++)
|
||||
{
|
||||
buffer.Clear();
|
||||
|
||||
for (var i = 0; i < settings.Length; i++)
|
||||
{
|
||||
buffer.Append(_chars[_random.Next(0, _chars.Length)]);
|
||||
}
|
||||
|
||||
foreach (var writer in output.GetWriters(settings.Target))
|
||||
{
|
||||
await writer.WriteLineAsync(buffer.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
40
src/process.dummy.app/_commands/LengthCommand.cs
Normal file
40
src/process.dummy.app/_commands/LengthCommand.cs
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
// 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;
|
||||
}
|
||||
}
|
||||
34
src/process.dummy.app/_commands/SleepCommand.cs
Normal file
34
src/process.dummy.app/_commands/SleepCommand.cs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
// Copyright (c) The Geekeey Authors
|
||||
// SPDX-License-Identifier: EUPL-1.2
|
||||
|
||||
using Spectre.Console.Cli;
|
||||
|
||||
internal sealed class SleepCommand : AsyncCommand<SleepCommand.Settings>
|
||||
{
|
||||
public sealed class Settings : CommandSettings
|
||||
{
|
||||
[CommandArgument(0, "[duration]")] public TimeSpan Duration { get; init; } = TimeSpan.FromSeconds(1);
|
||||
}
|
||||
|
||||
public override async Task<int> ExecuteAsync(CommandContext context, Settings settings, CancellationToken cancellationToken)
|
||||
{
|
||||
using var output = Output.Connect();
|
||||
|
||||
try
|
||||
{
|
||||
await Console.Out.WriteLineAsync($"Sleeping for {settings.Duration}...");
|
||||
await Console.Out.FlushAsync(CancellationToken.None);
|
||||
|
||||
await Task.Delay(settings.Duration, output.CancellationToken);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
await Console.Out.WriteLineAsync("Canceled.");
|
||||
await Console.Out.FlushAsync(CancellationToken.None);
|
||||
}
|
||||
|
||||
await Console.Out.WriteLineAsync("Done.");
|
||||
await Console.Out.FlushAsync(CancellationToken.None);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
23
src/process.dummy.app/_commands/WorkingDirectoryCommand.cs
Normal file
23
src/process.dummy.app/_commands/WorkingDirectoryCommand.cs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
// Copyright (c) The Geekeey Authors
|
||||
// SPDX-License-Identifier: EUPL-1.2
|
||||
|
||||
using Spectre.Console.Cli;
|
||||
|
||||
internal sealed class WorkingDirectoryCommand : AsyncOutputCommand<WorkingDirectoryCommand.Settings>
|
||||
{
|
||||
public sealed class Settings : OutputCommandSettings
|
||||
{
|
||||
}
|
||||
|
||||
public override async Task<int> ExecuteAsync(CommandContext context, Settings settings, CancellationToken cancellationToken)
|
||||
{
|
||||
using var output = Output.Connect();
|
||||
|
||||
foreach (var writer in output.GetWriters(settings.Target))
|
||||
{
|
||||
await writer.WriteLineAsync(Directory.GetCurrentDirectory());
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue