feat: remove spectre.console
Replace `Spectre.Console.Cli` with `System.CommandLine`
This commit is contained in:
parent
48c483c568
commit
d5629a49a9
14 changed files with 150 additions and 134 deletions
|
|
@ -1,23 +1,29 @@
|
|||
// Copyright (c) The Geekeey Authors
|
||||
// SPDX-License-Identifier: EUPL-1.2
|
||||
|
||||
using Spectre.Console.Cli;
|
||||
using System.CommandLine;
|
||||
|
||||
internal sealed class EchoCommand : AsyncOutputCommand<EchoCommand.Settings>
|
||||
internal sealed class EchoCommand : Command
|
||||
{
|
||||
public sealed class Settings : OutputCommandSettings
|
||||
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")
|
||||
{
|
||||
[CommandOption("--separator <char>")] public string Separator { get; init; } = " ";
|
||||
[CommandArgument(0, "[line]")] public string[] Items { get; init; } = [];
|
||||
Add(Target);
|
||||
Add(Separator);
|
||||
Add(Items);
|
||||
SetAction(ExecuteAsync);
|
||||
}
|
||||
|
||||
public override async Task<int> ExecuteAsync(CommandContext context, Settings settings, CancellationToken cancellationToken)
|
||||
public async Task<int> ExecuteAsync(ParseResult result, CancellationToken cancellationToken)
|
||||
{
|
||||
using var output = Output.Connect();
|
||||
|
||||
foreach (var writer in output.GetWriters(settings.Target))
|
||||
foreach (var writer in output.GetWriters(result.GetValue(Target)))
|
||||
{
|
||||
await writer.WriteLineAsync(string.Join(settings.Separator, settings.Items));
|
||||
await writer.WriteLineAsync(string.Join(result.GetRequiredValue(Separator), result.GetRequiredValue(Items)));
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue