mirror of
https://github.com/Govor-team/Govor.git
synced 2026-07-22 20:24:55 +00:00
Refactor console client to new Govor.ConsoleClient project
Removed Govor.Console implementation and introduced a new Govor.ConsoleClient project with a modular command-based architecture. Added dependency injection, command dispatcher, middleware pipeline, logging, and interactive command support. Updated solution and project files to reflect the new structure.
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
using Govor.ConsoleClient.Services;
|
||||
|
||||
namespace Govor.ConsoleClient.Commands;
|
||||
|
||||
public class HelpCommand : ICommand
|
||||
{
|
||||
public Task ExecuteAsync(CommandContext context)
|
||||
{
|
||||
Console.WriteLine("Commands:");
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public string LongHelp()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public string ShortHelp()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using Govor.ConsoleClient.Services;
|
||||
|
||||
namespace Govor.ConsoleClient.Commands;
|
||||
|
||||
public interface ICommand
|
||||
{
|
||||
Task ExecuteAsync(CommandContext context);
|
||||
string LongHelp();
|
||||
string ShortHelp();
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public class CommandRouteAttribute : Attribute
|
||||
{
|
||||
public string Path { get; }
|
||||
public CommandRouteAttribute(string path) => Path = path;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Govor.ConsoleClient.Commands;
|
||||
|
||||
public interface IInteractiveCommand : ICommand
|
||||
{
|
||||
Task HandleInputAsync(string input);
|
||||
bool IsCompleted { get; }
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
using Govor.ConsoleClient.Services;
|
||||
|
||||
namespace Govor.ConsoleClient.Commands;
|
||||
|
||||
[CommandRoute("/send")]
|
||||
public class SendMessageCommand : IInteractiveCommand
|
||||
{
|
||||
private string? _recipient;
|
||||
private bool _isCompleted;
|
||||
public bool IsCompleted => _isCompleted;
|
||||
|
||||
public Task ExecuteAsync(CommandContext context)
|
||||
{
|
||||
Console.WriteLine("Кому вы хотите отправить сообщение?");
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public async Task HandleInputAsync(string input)
|
||||
{
|
||||
if (_recipient == null)
|
||||
{
|
||||
_recipient = input;
|
||||
Console.WriteLine("Введите сообщение:");
|
||||
}
|
||||
else
|
||||
{
|
||||
var message = input;
|
||||
Console.WriteLine($"(Отправка '{message}' пользователю '{_recipient}')");
|
||||
_isCompleted = true;
|
||||
}
|
||||
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
|
||||
public string LongHelp()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public string ShortHelp()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user