using Microsoft.Extensions.Logging; using System; using System.CommandLine; using System.CommandLine.Invocation; using System.CommandLine.IO; using System.CommandLine.Rendering; using System.Threading.Tasks; namespace CustomHostingDemo { public class HelloCommand : CustomCommand { public HelloCommand() : base("hello", "says hello", typeof(DefaultHandler)) { AddArgument(new Argument("date", () => DateTime.Today)); AddOption(new Option("--verbose")); } public class HelloArgs { public DateTime Date { get; set; } public bool Verbose { get; set; } } public class DefaultHandler : ICommandHandler { private readonly ILogger _logger; public DefaultHandler(Logger logger) { _logger = logger; } public Task InvokeAsync(InvocationContext context, HelloArgs args) { context.Console.Out.WriteLine("Hello YOU!"); context.Console.Out.WriteLine($"P: --date {args.Date}"); context.Console.Out.WriteLine($"P: --verbose {args.Verbose}"); _logger.LogInformation("INFO from DefaultHandler"); return Task.FromResult(3); } } } }