build: initial project release
All checks were successful
release / dotnet-release-workflow (push) Successful in 1m23s
All checks were successful
release / dotnet-release-workflow (push) Successful in 1m23s
This commit is contained in:
commit
48c483c568
62 changed files with 4957 additions and 0 deletions
6
src/process.dummy.app/.editorconfig
Normal file
6
src/process.dummy.app/.editorconfig
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
|
||||
[*.{cs,vb}]
|
||||
# disable IDE0060: Remove unused parameter
|
||||
dotnet_diagnostic.IDE0060.severity = none
|
||||
# disable IDE0005: Unnecessary using directive
|
||||
dotnet_diagnostic.IDE0005.severity = none
|
||||
13
src/process.dummy.app/AsyncOutputCommand.cs
Normal file
13
src/process.dummy.app/AsyncOutputCommand.cs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
// Copyright (c) The Geekeey Authors
|
||||
// SPDX-License-Identifier: EUPL-1.2
|
||||
|
||||
using Spectre.Console.Cli;
|
||||
|
||||
internal abstract class AsyncOutputCommand<T> : AsyncCommand<T> where T : OutputCommandSettings
|
||||
{
|
||||
}
|
||||
|
||||
internal abstract class OutputCommandSettings : CommandSettings
|
||||
{
|
||||
[CommandOption("--target")] public OutputTarget Target { get; init; } = OutputTarget.StdOut;
|
||||
}
|
||||
17
src/process.dummy.app/Geekeey.Process.Dummy.App.csproj
Normal file
17
src/process.dummy.app/Geekeey.Process.Dummy.App.csproj
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<RootNamespace>Geekeey.Process</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Spectre.Console" PrivateAssets="compile" />
|
||||
<PackageReference Include="Spectre.Console.Cli" PrivateAssets="compile" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
42
src/process.dummy.app/Output.cs
Normal file
42
src/process.dummy.app/Output.cs
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
// Copyright (c) The Geekeey Authors
|
||||
// SPDX-License-Identifier: EUPL-1.2
|
||||
|
||||
internal sealed class Output : IDisposable
|
||||
{
|
||||
private readonly CancellationTokenSource _cts = new();
|
||||
|
||||
public Output()
|
||||
{
|
||||
Console.CancelKeyPress += Cancel;
|
||||
}
|
||||
|
||||
public StreamReader Stdin { get; } = new(Console.OpenStandardInput(), leaveOpen: false);
|
||||
|
||||
public StreamWriter Stdout { get; } = new(Console.OpenStandardOutput(), leaveOpen: false);
|
||||
|
||||
public StreamWriter Stderr { get; } = new(Console.OpenStandardError(), leaveOpen: false);
|
||||
|
||||
public CancellationToken CancellationToken => _cts.Token;
|
||||
|
||||
public static Output Connect()
|
||||
{
|
||||
return new Output();
|
||||
}
|
||||
|
||||
private void Cancel(object? sender, ConsoleCancelEventArgs args)
|
||||
{
|
||||
args.Cancel = true;
|
||||
_cts.Cancel();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Stdout.BaseStream.Flush();
|
||||
Stdout.Dispose();
|
||||
Stderr.BaseStream.Flush();
|
||||
Stderr.Dispose();
|
||||
Stdin.Dispose();
|
||||
Console.CancelKeyPress -= Cancel;
|
||||
_cts.Dispose();
|
||||
}
|
||||
}
|
||||
26
src/process.dummy.app/OutputTarget.cs
Normal file
26
src/process.dummy.app/OutputTarget.cs
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
// Copyright (c) The Geekeey Authors
|
||||
// SPDX-License-Identifier: EUPL-1.2
|
||||
|
||||
[Flags]
|
||||
internal enum OutputTarget
|
||||
{
|
||||
StdOut = 1,
|
||||
StdErr = 2,
|
||||
All = StdOut | StdErr
|
||||
}
|
||||
|
||||
internal static class OutputTargetExtensions
|
||||
{
|
||||
public static IEnumerable<StreamWriter> GetWriters(this Output output, OutputTarget target)
|
||||
{
|
||||
if (target.HasFlag(OutputTarget.StdOut))
|
||||
{
|
||||
yield return output.Stdout;
|
||||
}
|
||||
|
||||
if (target.HasFlag(OutputTarget.StdErr))
|
||||
{
|
||||
yield return output.Stderr;
|
||||
}
|
||||
}
|
||||
}
|
||||
45
src/process.dummy.app/Program.cs
Normal file
45
src/process.dummy.app/Program.cs
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
// Copyright (c) The Geekeey Authors
|
||||
// SPDX-License-Identifier: EUPL-1.2
|
||||
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using Spectre.Console.Cli;
|
||||
|
||||
namespace Geekeey.Process.Testing.Fixture;
|
||||
|
||||
public static class Program
|
||||
{
|
||||
private static readonly string? FileExtension = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "exe" : null;
|
||||
|
||||
#pragma warning disable IL3000 // only for testing where we don't run in single files!
|
||||
private static readonly string AssemblyPath = Assembly.GetExecutingAssembly().Location;
|
||||
#pragma warning restore IL3000
|
||||
|
||||
public static string FilePath { get; } = Path.ChangeExtension(AssemblyPath, FileExtension);
|
||||
|
||||
private static Task<int> Main(string[] args)
|
||||
{
|
||||
Environment.SetEnvironmentVariable("DOTNET_SYSTEM_CONSOLE_ALLOW_ANSI_COLOR_REDIRECTION", "false");
|
||||
var app = new CommandApp();
|
||||
app.Configure(Configuration);
|
||||
return app.RunAsync(args);
|
||||
|
||||
static void Configuration(IConfigurator configuration)
|
||||
{
|
||||
configuration.AddCommand<EchoCommand>("echo");
|
||||
configuration.AddCommand<EchoStdinCommand>("echo-stdin");
|
||||
configuration.AddCommand<EnvironmentCommand>("env");
|
||||
configuration.AddCommand<WorkingDirectoryCommand>("cwd");
|
||||
configuration.AddCommand<WorkingDirectoryCommand>("cwd");
|
||||
configuration.AddCommand<ExitCommand>("exit");
|
||||
configuration.AddCommand<LengthCommand>("length");
|
||||
configuration.AddCommand<SleepCommand>("sleep");
|
||||
configuration.AddBranch("generate", static generate =>
|
||||
{
|
||||
generate.AddCommand<GenerateBlobCommand>("blob");
|
||||
generate.AddCommand<GenerateClobCommand>("clob");
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
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