mirror of
https://github.com/parnic/advent-of-code-2022.git
synced 2025-06-16 05:30:14 -05:00
Add ability to run multiple days from command line
Also add timing for the entire program run.
This commit is contained in:
34
src/main.cs
34
src/main.cs
@ -1,5 +1,6 @@
|
||||
using aoc2022;
|
||||
|
||||
using aoc2022.Timer t = new("Full program");
|
||||
var types = System.Reflection.Assembly
|
||||
.GetExecutingAssembly()
|
||||
.GetTypes()
|
||||
@ -9,7 +10,7 @@ var types = System.Reflection.Assembly
|
||||
bool runAll = false;
|
||||
bool? runPart1 = null;
|
||||
bool? runPart2 = null;
|
||||
string? desiredDay = null;
|
||||
List<string> desiredDays = new();
|
||||
foreach (var arg in args)
|
||||
{
|
||||
if (arg.Equals("-part1", StringComparison.CurrentCultureIgnoreCase))
|
||||
@ -26,7 +27,7 @@ foreach (var arg in args)
|
||||
}
|
||||
else
|
||||
{
|
||||
desiredDay = arg;
|
||||
desiredDays.Add(arg);
|
||||
}
|
||||
}
|
||||
|
||||
@ -46,23 +47,32 @@ if (runAll)
|
||||
}
|
||||
else
|
||||
{
|
||||
Day? day = null;
|
||||
if (string.IsNullOrEmpty(desiredDay))
|
||||
if (desiredDays.Count == 0)
|
||||
{
|
||||
day = (Day)Activator.CreateInstance(types.Last())!;
|
||||
desiredDays.Add("");
|
||||
}
|
||||
else
|
||||
|
||||
foreach (var desiredDay in desiredDays)
|
||||
{
|
||||
var type = types.FirstOrDefault(x => x.Name == $"Day{desiredDay.PadLeft(2, '0')}");
|
||||
if (type == null)
|
||||
Day? day = null;
|
||||
if (string.IsNullOrEmpty(desiredDay))
|
||||
{
|
||||
Logger.Log($"Unknown day <cyan>{desiredDay}<r>");
|
||||
day = (Day) Activator.CreateInstance(types.Last())!;
|
||||
}
|
||||
else
|
||||
{
|
||||
day = (Day?)Activator.CreateInstance(type);
|
||||
var type = types.FirstOrDefault(x => x.Name == $"Day{desiredDay.PadLeft(2, '0')}");
|
||||
if (type == null)
|
||||
{
|
||||
Logger.Log($"Unknown day <cyan>{desiredDay}<r>");
|
||||
}
|
||||
else
|
||||
{
|
||||
day = (Day?) Activator.CreateInstance(type);
|
||||
}
|
||||
}
|
||||
|
||||
day?.Go(runPart1 ?? true, runPart2 ?? true);
|
||||
day?.Dispose();
|
||||
}
|
||||
day?.Go(runPart1 ?? true, runPart2 ?? true);
|
||||
day?.Dispose();
|
||||
}
|
||||
|
Reference in New Issue
Block a user