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"); var span = new ContainerSpan(StyleSpan.UnderlinedOn(), new ContentSpan("Underlining"), StyleSpan.UnderlinedOff()); context.Console.Out.WriteLine(span.ToString(OutputMode.Auto)); context.Console.Out.WriteLine(new ContainerSpan( ForegroundColorSpan.LightGreen(), StyleSpan.BlinkOn(), new ContentSpan("Blinking"), StyleSpan.BlinkOff(), new ContentSpan("Noblink"), ForegroundColorSpan.Reset(), new ContentSpan("Normal") ).ToString(OutputMode.Ansi)); return Task.FromResult(3); } } } }