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("--verbose")); } public class DefaultHandler : ICommandHandler { private readonly IResolutionRoot _resolutionRoot; public bool Verbose { get; set; } public DefaultHandler(IResolutionRoot resolutionRoot) { _resolutionRoot = resolutionRoot; } public Task InvokeAsync(InvocationContext context) { context.Console.Out.WriteLine("Hello YOU!"); context.Console.Out.WriteLine($"C: --verbose {Verbose}"); return Task.FromResult(0); } } } }