37 lines
890 B
C#
37 lines
890 B
C#
|
|
using System.Reflection;
|
|
using AdventOfCode.Days;
|
|
using Spectre.Console;
|
|
|
|
var days = Assembly.GetAssembly(typeof(Day))!.GetTypes()
|
|
.Where(t => t.IsAssignableTo(typeof(Day)) && t.GetConstructor(Type.EmptyTypes) != null && !t.IsAbstract)
|
|
.Select(t => (Day)Activator.CreateInstance(t)!);
|
|
|
|
var select = new SelectionPrompt<Day>()
|
|
.Title("[cyan]Select a [yellow]day[/] to run:[/]")
|
|
.AddChoices(days.OrderByDescending(d => d.Number));
|
|
|
|
var selectedDay = AnsiConsole.Prompt(select);
|
|
|
|
AnsiConsole.MarkupLine($"[cyan]Running [yellow]{selectedDay}[/]...[/]\n");
|
|
|
|
AnsiConsole.MarkupLine("[cyan]Part [yellow]1[/] result:[/]");
|
|
|
|
try
|
|
{
|
|
selectedDay.RunPart1();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
AnsiConsole.WriteException(e);
|
|
}
|
|
|
|
AnsiConsole.MarkupLine("\n[cyan]Part [yellow]2[/] result:[/]");
|
|
try
|
|
{
|
|
selectedDay.RunPart2();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
AnsiConsole.WriteException(e);
|
|
} |