| 123456789101112131415161718192021222324252627282930313233343536373839404142 |
- using Ninject.Syntax;
- 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.Threading.Tasks;
- namespace CustomHostingDemo
- {
- public class HelloCommand : Command
- {
- public HelloCommand()
- : base("hello", "says hello")
- {
- Handler = CommandHandler.Create(typeof(DefaultHandler).GetMethod(nameof(ICommandHandler.InvokeAsync)));
- AddOption(new Option<bool>("--verbose"));
- }
- public class DefaultHandler : ICommandHandler
- {
- private readonly IResolutionRoot _resolutionRoot;
- public bool Verbose { get; set; }
- public DefaultHandler(IResolutionRoot resolutionRoot)
- {
- _resolutionRoot = resolutionRoot;
- }
- public Task<int> InvokeAsync(InvocationContext context)
- {
- context.Console.Out.WriteLine("Hello YOU!");
- context.Console.Out.WriteLine($"C: --verbose {Verbose}");
- return Task.FromResult(0);
- }
- }
- }
- }
|