using System.Threading.Tasks; using CliFx.Attributes; using CliFx.Demo.Domain; using CliFx.Demo.Utils; using CliFx.Exceptions; using CliFx.Infrastructure; namespace CliFx.Demo.Commands; [Command("book", Description = "Retrieves a book from the library.")] public class BookCommand(LibraryProvider libraryProvider) : ICommand { [CommandParameter(0, Name = "title", Description = "Title of the book to retrieve.")] public required string Title { get; init; } public ValueTask ExecuteAsync(IConsole console) { var book = libraryProvider.TryGetBook(Title); if (book is null) throw new CommandException("Book not found.", 10); console.Output.WriteBook(book); return default; } }