From 00e8303b902e8ab0c51f1c29fd14d9b5f7c914e6 Mon Sep 17 00:00:00 2001 From: Eveldee Date: Mon, 5 Dec 2022 11:02:18 +0100 Subject: [PATCH] Add day selector --- .gitignore | 6 ++++++ AdventOfCode.csproj | 14 ++++++++++++++ AdventOfCode.sln | 16 ++++++++++++++++ Days/Day.cs | 14 ++++++++++++++ Days/Day1.cs | 14 ++++++++++++++ Days/Day2.cs | 14 ++++++++++++++ Program.cs | 18 ++++++++++++++++++ 7 files changed, 96 insertions(+) create mode 100644 .gitignore create mode 100644 AdventOfCode.csproj create mode 100644 AdventOfCode.sln create mode 100644 Days/Day.cs create mode 100644 Days/Day1.cs create mode 100644 Days/Day2.cs create mode 100644 Program.cs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..679a700 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +bin/ +obj/ +/packages/ +riderModule.iml +/_ReSharper.Caches/ +.idea/.idea.AdventOfCode/.idea \ No newline at end of file diff --git a/AdventOfCode.csproj b/AdventOfCode.csproj new file mode 100644 index 0000000..efbbd57 --- /dev/null +++ b/AdventOfCode.csproj @@ -0,0 +1,14 @@ + + + + Exe + net7.0 + enable + enable + + + + + + + diff --git a/AdventOfCode.sln b/AdventOfCode.sln new file mode 100644 index 0000000..054846c --- /dev/null +++ b/AdventOfCode.sln @@ -0,0 +1,16 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AdventOfCode", "AdventOfCode.csproj", "{566CA1D9-1EDC-491C-8196-CA163F9D6FE1}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {566CA1D9-1EDC-491C-8196-CA163F9D6FE1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {566CA1D9-1EDC-491C-8196-CA163F9D6FE1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {566CA1D9-1EDC-491C-8196-CA163F9D6FE1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {566CA1D9-1EDC-491C-8196-CA163F9D6FE1}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/Days/Day.cs b/Days/Day.cs new file mode 100644 index 0000000..f8e3635 --- /dev/null +++ b/Days/Day.cs @@ -0,0 +1,14 @@ +namespace AdventOfCode.Days; + +public abstract class Day +{ + public abstract int Number { get; } + public abstract string Name { get; } + + public abstract void Run(); + + public override string ToString() + { + return $"Day {Number}: {Name}"; + } +} \ No newline at end of file diff --git a/Days/Day1.cs b/Days/Day1.cs new file mode 100644 index 0000000..c434648 --- /dev/null +++ b/Days/Day1.cs @@ -0,0 +1,14 @@ +using Spectre.Console; + +namespace AdventOfCode.Days; + +public class Day1 : Day +{ + public override int Number => 1; + public override string Name => "First day"; + + public override void Run() + { + AnsiConsole.WriteLine("Day 1 result"); + } +} \ No newline at end of file diff --git a/Days/Day2.cs b/Days/Day2.cs new file mode 100644 index 0000000..812bbaa --- /dev/null +++ b/Days/Day2.cs @@ -0,0 +1,14 @@ +using Spectre.Console; + +namespace AdventOfCode.Days; + +public class Day2 : Day +{ + public override int Number { get; } = 2; + public override string Name { get; } = "Second day"; + + public override void Run() + { + AnsiConsole.WriteLine("Day 2 result"); + } +} \ No newline at end of file diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..aa9ce43 --- /dev/null +++ b/Program.cs @@ -0,0 +1,18 @@ + +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() + .Title("[cyan]Select a [yellow]day[/] to run:[/]") + .AddChoices(days); + +var selectedDay = AnsiConsole.Prompt(select); + +AnsiConsole.MarkupLine($"[cyan]Running [yellow]{selectedDay}[/]...[/]\n"); + +selectedDay.Run(); \ No newline at end of file