|
|
@@ -1,9 +1,8 @@
|
|
|
-using Microsoft.Extensions.Logging;
|
|
|
+using CustomHostingDemo.Logging;
|
|
|
+using Microsoft.Extensions.Configuration;
|
|
|
using System;
|
|
|
using System.CommandLine;
|
|
|
using System.CommandLine.Invocation;
|
|
|
-using System.CommandLine.IO;
|
|
|
-using System.CommandLine.Rendering;
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
namespace CustomHostingDemo
|
|
|
@@ -17,7 +16,7 @@ namespace CustomHostingDemo
|
|
|
AddOption(new Option<bool>("--verbose"));
|
|
|
}
|
|
|
|
|
|
- public class HelloArgs
|
|
|
+ public class HelloArgs : IDefaultArgs
|
|
|
{
|
|
|
public DateTime Date { get; set; }
|
|
|
public bool Verbose { get; set; }
|
|
|
@@ -25,40 +24,22 @@ namespace CustomHostingDemo
|
|
|
|
|
|
public class DefaultHandler : ICommandHandler<HelloArgs>
|
|
|
{
|
|
|
- private readonly ILogger _logger;
|
|
|
- private readonly ILog _log;
|
|
|
+ private readonly ICliLogger _logger;
|
|
|
+ private readonly IConfiguration _config;
|
|
|
|
|
|
- public DefaultHandler(Logger<DefaultHandler> logger, ILog log)
|
|
|
+ public DefaultHandler(ICliLogger logger, IConfiguration config)
|
|
|
{
|
|
|
_logger = logger;
|
|
|
- _log = log;
|
|
|
+ _config = config;
|
|
|
}
|
|
|
|
|
|
public Task<int> InvokeAsync(InvocationContext context, HelloArgs args)
|
|
|
{
|
|
|
- _log.LogMessage("Hello YOU!");
|
|
|
- _log.LogMessage($"P: --date {args.Date}");
|
|
|
- _log.LogMessage($"P: --verbose {args.Verbose}");
|
|
|
+ _logger.LogContent($"Hello {_config["Hello"]}! How are you?");
|
|
|
+ _logger.LogInfo($"P: --date {args.Date}");
|
|
|
+ _logger.LogInfo($"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);
|
|
|
+ return Task.FromResult(0);
|
|
|
}
|
|
|
}
|
|
|
}
|