|
|
@@ -1,21 +1,18 @@
|
|
|
-using Ninject.Syntax;
|
|
|
+using Microsoft.Extensions.Logging;
|
|
|
using System;
|
|
|
-using System.Collections.Generic;
|
|
|
using System.CommandLine;
|
|
|
using System.CommandLine.Invocation;
|
|
|
using System.CommandLine.IO;
|
|
|
-using System.Linq;
|
|
|
-using System.Text;
|
|
|
+using System.CommandLine.Rendering;
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
namespace CustomHostingDemo
|
|
|
{
|
|
|
- public class HelloCommand : Command
|
|
|
+ public class HelloCommand : CustomCommand<HelloCommand.HelloArgs>
|
|
|
{
|
|
|
public HelloCommand()
|
|
|
- : base("hello", "says hello")
|
|
|
+ : base("hello", "says hello", typeof(DefaultHandler))
|
|
|
{
|
|
|
- Handler = CommandHandler.Create(typeof(DefaultHandler).GetMethod(nameof(ICommandHandler.InvokeAsync)));
|
|
|
AddArgument(new Argument<DateTime>("date", () => DateTime.Today));
|
|
|
AddOption(new Option<bool>("--verbose"));
|
|
|
}
|
|
|
@@ -26,24 +23,24 @@ namespace CustomHostingDemo
|
|
|
public bool Verbose { get; set; }
|
|
|
}
|
|
|
|
|
|
- public class DefaultHandler : ICommandHandler
|
|
|
+ public class DefaultHandler : ICommandHandler<HelloArgs>
|
|
|
{
|
|
|
- private readonly HelloArgs _args;
|
|
|
- private readonly IResolutionRoot _resolutionRoot;
|
|
|
+ private readonly ILogger _logger;
|
|
|
|
|
|
- public DefaultHandler(HelloArgs args, IResolutionRoot resolutionRoot)
|
|
|
+ public DefaultHandler(Logger<DefaultHandler> logger)
|
|
|
{
|
|
|
- _args = args;
|
|
|
- _resolutionRoot = resolutionRoot;
|
|
|
+ _logger = logger;
|
|
|
}
|
|
|
|
|
|
- public Task<int> InvokeAsync(InvocationContext context)
|
|
|
+ public Task<int> 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}");
|
|
|
+ context.Console.Out.WriteLine($"P: --date {args.Date}");
|
|
|
+ context.Console.Out.WriteLine($"P: --verbose {args.Verbose}");
|
|
|
|
|
|
- return Task.FromResult(0);
|
|
|
+ _logger.LogInformation("INFO from DefaultHandler");
|
|
|
+
|
|
|
+ return Task.FromResult(3);
|
|
|
}
|
|
|
}
|
|
|
}
|