Skip to content

Commit

Permalink
Another primary constructor update
Browse files Browse the repository at this point in the history
  • Loading branch information
jakenuts committed Aug 19, 2024
1 parent bef8bca commit aeef6eb
Showing 1 changed file with 7 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,27 @@
namespace Community.Extensions.Spectre.Cli.Hosting.Sample.Commands;

/// <summary>
/// Creates a HelloCommand with access to services, the console and logging
/// </summary>
public class HelloCommand : AsyncCommand<HelloCommand.Options>
/// <param name="serviceProvider"></param>
/// <param name="console"></param>
public class HelloCommand(IServiceProvider serviceProvider, IAnsiConsole console) : AsyncCommand<HelloCommand.Options>
{
private readonly IAnsiConsole _console;

private readonly IServiceProvider _serviceProvider;

/// <summary>
/// Creates a HelloCommand with access to services, the console and logging
/// </summary>
/// <param name="serviceProvider"></param>
/// <param name="console"></param>
/// <param name="log"></param>
public HelloCommand(IServiceProvider serviceProvider, IAnsiConsole console, ILogger<HelloCommand> log)
{
_serviceProvider = serviceProvider;
_console = console;
}

/// <summary>Executes the command.</summary>
/// <param name="context">The command context.</param>
/// <param name="options">The command options.</param>
/// <returns>An integer indicating whether or not the command executed successfully.</returns>
public override async Task<int> ExecuteAsync(CommandContext context, Options options)
{
await using var scope = _serviceProvider.CreateAsyncScope();
await using var scope = serviceProvider.CreateAsyncScope();

// var coolService = scope.ServiceProvider.GetRequiredService<ITheCoolestService>();

_console.MarkupLineInterpolated($"[darkseagreen2_1] Hello {options.Name}![/]");
console.MarkupLineInterpolated($"[darkseagreen2_1] Hello {options.Name}![/]");

if (!string.IsNullOrEmpty(options.DogsName))
{
_console.MarkupLineInterpolated($"[darkseagreen2_1] Ooooo who's a good pup? {options.DogsName} thats who! 🐶[/]");
console.MarkupLineInterpolated($"[darkseagreen2_1] Ooooo who's a good pup? {options.DogsName} thats who! 🐶[/]");
}

return 0;
Expand Down

0 comments on commit aeef6eb

Please sign in to comment.