Add ability to run multiple days from command line

Also add timing for the entire program run.
This commit is contained in:
2022-12-16 08:42:13 -06:00
parent fdf621b58d
commit fcfdb7146b

View File

@ -1,5 +1,6 @@
using aoc2022; using aoc2022;
using aoc2022.Timer t = new("Full program");
var types = System.Reflection.Assembly var types = System.Reflection.Assembly
.GetExecutingAssembly() .GetExecutingAssembly()
.GetTypes() .GetTypes()
@ -9,7 +10,7 @@ var types = System.Reflection.Assembly
bool runAll = false; bool runAll = false;
bool? runPart1 = null; bool? runPart1 = null;
bool? runPart2 = null; bool? runPart2 = null;
string? desiredDay = null; List<string> desiredDays = new();
foreach (var arg in args) foreach (var arg in args)
{ {
if (arg.Equals("-part1", StringComparison.CurrentCultureIgnoreCase)) if (arg.Equals("-part1", StringComparison.CurrentCultureIgnoreCase))
@ -26,7 +27,7 @@ foreach (var arg in args)
} }
else else
{ {
desiredDay = arg; desiredDays.Add(arg);
} }
} }
@ -46,23 +47,32 @@ if (runAll)
} }
else else
{ {
Day? day = null; if (desiredDays.Count == 0)
if (string.IsNullOrEmpty(desiredDay))
{ {
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')}"); Day? day = null;
if (type == null) if (string.IsNullOrEmpty(desiredDay))
{ {
Logger.Log($"Unknown day <cyan>{desiredDay}<r>"); day = (Day) Activator.CreateInstance(types.Last())!;
} }
else 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();
} }