You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
2.9 KiB

using AdventOfCode.Contracts;
using Mono.Options;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
namespace AdventOfCode
{
class Program
{
private static bool Help { get; set; }
private static bool BigBoi { get; set; }
private static List<int> Year { get; set; } = new List<int>();
private static List<int> Day { get; set; } = new List<int>();
private static void Main(string[] args)
{
OptionSet options = new OptionSet()
{
{ "h|?|help", "Prints this help message and exits", s => Help = s != null },
{ "y|year=", "The year of the challenge", (int s) => Year.Add(s) },
{ "d|day=", "The day(s) of the challenge. Accepts multiple (-d 1, -day=2)", (int s) => Day.Add(s) },
{ "b|BigBoi", "Tells the program if it should run the BigBoi input", s => BigBoi = s != null}
};
try
{
options.Parse(args);
}
catch (OptionException e)
{
Error(e.Message);
Exit();
return;
}
if (Help)
{
Console.WriteLine("Usage: dotnet ./AoC.dll [OPTIONS]");
Console.WriteLine("If no options are provided, all years and days will be run.");
Console.WriteLine("If only a year is provided, all days from that year will be run.");
Console.WriteLine("If only a day is provided, the provided day from all years will be run.");
options.WriteOptionDescriptions(Console.Out);
return;
}
if (!Day.Any() && (Day.Min() < 0 || Day.Max() > 25))
{
Error("Days must be between 1 and 25.");
return;
}
var days = GetDays();
if (Day.Any())
{
days = days.Where(d => Day.Contains(d.DayNumber));
}
if (Year.Any())
{
days = days.Where(d => Year.Contains(d.Year));
}
foreach (Day d in days)
{
d.Execute(BigBoi);
d.Write();
}
Exit();
}
private static void Error(string e)
{
Console.Write("Advent of Code:");
Console.WriteLine(e);
Console.WriteLine("Try AdventOfCode --help for more information");
}
private static void Exit()
{
Console.WriteLine("Press any key to exit.");
Console.ReadKey();
}
private static IEnumerable<Day> GetDays() =>
Assembly.GetExecutingAssembly()
.GetTypes()
.Where(t => t.BaseType == typeof(Day))
.Select(t => (Day)Activator.CreateInstance(t))
.OrderBy(t => t.Year)
.ThenBy(t => t.DayNumber);
}
}