using System; using System.CommandLine; using System.CommandLine.Invocation; using System.Threading.Tasks; using MfGames.ToolBuilder; namespace SampleTool { public class CrashTopCommand : Command, ITopCommand, ICommandHandler { private readonly Option messyOption; /// public CrashTopCommand() : base("crash", "Crash the application with an exception.") { this.Handler = this; this.messyOption = new Option("--messy"); this.AddOption(this.messyOption); } /// public Task InvokeAsync(InvocationContext context) { bool messy = context.ParseResult.ValueForOption(this.messyOption); if (messy) { throw new Exception( "This command crashed messily as requested."); } throw new ToolException("This command crashed as requested."); } } }