This repository has been archived on 2023-02-02. You can view files and clone it, but cannot push or open issues or pull requests.
mfgames-toolbuilder-cil/tests/SampleTool/CrashTopCommand.cs
Dylan R. E. Moonfire ad0525be04 feat: initial commit
2021-09-10 12:33:42 -05:00

38 lines
1 KiB
C#

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<bool> messyOption;
/// <inheritdoc />
public CrashTopCommand()
: base("crash", "Crash the application with an exception.")
{
this.Handler = this;
this.messyOption = new Option<bool>("--messy");
this.AddOption(this.messyOption);
}
/// <inheritdoc />
public Task<int> 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.");
}
}
}