2020-12-01 11:28:18 +00:00
|
|
|
import core.stdc.stdlib;
|
|
|
|
|
|
|
|
import std.conv;
|
|
|
|
import std.format;
|
2020-11-30 14:22:15 +00:00
|
|
|
import std.stdio;
|
2020-12-01 11:28:18 +00:00
|
|
|
import std.getopt;
|
|
|
|
|
|
|
|
import day1;
|
2020-12-02 16:53:43 +00:00
|
|
|
import day2;
|
2020-12-03 09:50:55 +00:00
|
|
|
import day3;
|
2020-12-01 14:42:11 +00:00
|
|
|
import dayutil;
|
2020-12-01 11:28:18 +00:00
|
|
|
|
|
|
|
immutable string progName = "aoc-2020";
|
|
|
|
|
|
|
|
void function(string[])[] programs = [
|
2020-12-02 16:53:43 +00:00
|
|
|
&day1.run,
|
2020-12-03 09:50:55 +00:00
|
|
|
&day2.run,
|
|
|
|
&day3.run,
|
2020-12-01 11:28:18 +00:00
|
|
|
];
|
|
|
|
|
2020-12-01 14:42:11 +00:00
|
|
|
void printUsage(string name) {
|
|
|
|
printUsage(name, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
void printUsage(string name, string message) {
|
|
|
|
stderr.writeln("USAGE: %s [day] [part]".format(name));
|
|
|
|
if (message != null) {
|
|
|
|
stderr.writeln(message);
|
|
|
|
}
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
|
2020-12-01 11:28:18 +00:00
|
|
|
void main(string[] args) {
|
|
|
|
int day;
|
|
|
|
if (args.length < 2) {
|
2020-12-01 14:42:11 +00:00
|
|
|
printUsage(args[0]);
|
2020-12-01 11:28:18 +00:00
|
|
|
}
|
|
|
|
try {
|
|
|
|
day = to!int(args[1]);
|
|
|
|
} catch (ConvException e) {
|
2020-12-01 14:42:11 +00:00
|
|
|
printUsage(args[0], "[day] is not an integer");
|
2020-12-01 11:28:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (day <= 0 || day > programs.length) {
|
2020-12-01 14:42:11 +00:00
|
|
|
printUsage(args[0], "[day] must be between 1 and %d".format(programs.length - 1));
|
2020-12-01 11:28:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-01 14:42:11 +00:00
|
|
|
try {
|
|
|
|
programs[day - 1](args[2..$]);
|
|
|
|
} catch(ArgumentException e) {
|
|
|
|
printUsage(args[0], e.msg);
|
|
|
|
}
|
2020-11-30 14:22:15 +00:00
|
|
|
|
|
|
|
}
|