43 lines
1.3 KiB
C#
43 lines
1.3 KiB
C#
using CommandDotNet;
|
|
using EnvelopeGenerator.Application.Contracts.Services;
|
|
using EnvelopeGenerator.Application.Documents.Queries.Read;
|
|
using MediatR;
|
|
using System.Reflection;
|
|
using System.Text.Json;
|
|
|
|
namespace EnvelopeGenerator.Terminal;
|
|
|
|
public class CommandManager
|
|
{
|
|
private static JsonSerializerOptions Options = new ()
|
|
{
|
|
WriteIndented = true
|
|
};
|
|
private readonly IEnvelopeReceiverService _envelopeReceiverService;
|
|
private readonly IMediator _mediator;
|
|
|
|
public CommandManager(IEnvelopeReceiverService envelopeReceiverService, IMediator mediator)
|
|
{
|
|
_envelopeReceiverService = envelopeReceiverService;
|
|
_mediator = mediator;
|
|
}
|
|
|
|
[DefaultCommand]
|
|
public void Execute([Option(Description = "print envelope generator termianal version.")] bool version)
|
|
{
|
|
if(version)
|
|
Console.WriteLine($"v{Assembly.GetExecutingAssembly().GetName().Version}");
|
|
}
|
|
|
|
[Subcommand]
|
|
public IEnvelopeReceiverService EnvelopeReceiver => _envelopeReceiverService;
|
|
|
|
[Command]
|
|
public async Task ReadDocument(IConsole console, int? id = null, int? envelopeId = null)
|
|
{
|
|
ReadDocumentQuery query = new(id, envelopeId);
|
|
var document = await _mediator.Send(query);
|
|
console.WriteLine(JsonSerializer.Serialize(document, Options));
|
|
}
|
|
}
|