|
@@ -16,24 +16,32 @@ namespace CustomHostingDemo
|
|
|
: base("hello", "says hello")
|
|
: base("hello", "says hello")
|
|
|
{
|
|
{
|
|
|
Handler = CommandHandler.Create(typeof(DefaultHandler).GetMethod(nameof(ICommandHandler.InvokeAsync)));
|
|
Handler = CommandHandler.Create(typeof(DefaultHandler).GetMethod(nameof(ICommandHandler.InvokeAsync)));
|
|
|
|
|
+ AddArgument(new Argument<DateTime>("date", () => DateTime.Today));
|
|
|
AddOption(new Option<bool>("--verbose"));
|
|
AddOption(new Option<bool>("--verbose"));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public class HelloArgs
|
|
|
|
|
+ {
|
|
|
|
|
+ public DateTime Date { get; set; }
|
|
|
|
|
+ public bool Verbose { get; set; }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public class DefaultHandler : ICommandHandler
|
|
public class DefaultHandler : ICommandHandler
|
|
|
{
|
|
{
|
|
|
|
|
+ private readonly HelloArgs _args;
|
|
|
private readonly IResolutionRoot _resolutionRoot;
|
|
private readonly IResolutionRoot _resolutionRoot;
|
|
|
|
|
|
|
|
- public bool Verbose { get; set; }
|
|
|
|
|
-
|
|
|
|
|
- public DefaultHandler(IResolutionRoot resolutionRoot)
|
|
|
|
|
|
|
+ public DefaultHandler(HelloArgs args, IResolutionRoot resolutionRoot)
|
|
|
{
|
|
{
|
|
|
|
|
+ _args = args;
|
|
|
_resolutionRoot = resolutionRoot;
|
|
_resolutionRoot = resolutionRoot;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public Task<int> InvokeAsync(InvocationContext context)
|
|
public Task<int> InvokeAsync(InvocationContext context)
|
|
|
{
|
|
{
|
|
|
context.Console.Out.WriteLine("Hello YOU!");
|
|
context.Console.Out.WriteLine("Hello YOU!");
|
|
|
- context.Console.Out.WriteLine($"C: --verbose {Verbose}");
|
|
|
|
|
|
|
+ context.Console.Out.WriteLine($"P: --date {_args.Date}");
|
|
|
|
|
+ context.Console.Out.WriteLine($"P: --verbose {_args.Verbose}");
|
|
|
|
|
|
|
|
return Task.FromResult(0);
|
|
return Task.FromResult(0);
|
|
|
}
|
|
}
|