2026-01-20 22:41:16 +01:00
|
|
|
// Copyright (c) The Geekeey Authors
|
|
|
|
|
// SPDX-License-Identifier: EUPL-1.2
|
|
|
|
|
|
2026-05-10 15:08:55 +02:00
|
|
|
using System.CommandLine;
|
2026-01-20 22:41:16 +01:00
|
|
|
|
2026-05-10 15:08:55 +02:00
|
|
|
internal sealed class EchoCommand : Command
|
2026-01-20 22:41:16 +01:00
|
|
|
{
|
2026-05-10 15:08:55 +02:00
|
|
|
private static readonly Option<OutputTarget> Target = new("--target") { DefaultValueFactory = _ => OutputTarget.StdOut };
|
|
|
|
|
private static readonly Option<string> Separator = new("--separator") { DefaultValueFactory = _ => " " };
|
|
|
|
|
private static readonly Argument<string[]> Items = new("line") { Arity = ArgumentArity.ZeroOrMore, DefaultValueFactory = _ => [] };
|
|
|
|
|
|
|
|
|
|
public EchoCommand() : base("echo")
|
2026-01-20 22:41:16 +01:00
|
|
|
{
|
2026-05-10 15:08:55 +02:00
|
|
|
Add(Target);
|
|
|
|
|
Add(Separator);
|
|
|
|
|
Add(Items);
|
|
|
|
|
SetAction(ExecuteAsync);
|
2026-01-20 22:41:16 +01:00
|
|
|
}
|
|
|
|
|
|
2026-05-10 15:08:55 +02:00
|
|
|
public async Task<int> ExecuteAsync(ParseResult result, CancellationToken cancellationToken)
|
2026-01-20 22:41:16 +01:00
|
|
|
{
|
|
|
|
|
using var output = Output.Connect();
|
|
|
|
|
|
2026-05-10 15:08:55 +02:00
|
|
|
foreach (var writer in output.GetWriters(result.GetValue(Target)))
|
2026-01-20 22:41:16 +01:00
|
|
|
{
|
2026-05-10 15:08:55 +02:00
|
|
|
await writer.WriteLineAsync(string.Join(result.GetRequiredValue(Separator), result.GetRequiredValue(Items)));
|
2026-01-20 22:41:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2026-05-16 12:25:38 +02:00
|
|
|
}
|