2022-11-06 21:12:30 -08:00
|
|
|
#include <aocpp/Startup.hpp>
|
|
|
|
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <iostream>
|
2022-11-07 21:00:14 -08:00
|
|
|
#include <optional>
|
|
|
|
#include <memory>
|
2022-11-06 21:12:30 -08:00
|
|
|
#include <fstream>
|
2022-11-13 11:42:40 -08:00
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
#define DOCTEST_CONFIG_IMPLEMENT
|
|
|
|
#include <doctest.h>
|
2022-11-06 21:12:30 -08:00
|
|
|
|
|
|
|
namespace aocpp {
|
|
|
|
|
2023-01-14 20:00:55 -08:00
|
|
|
auto Startup(int argc, char ** argv) -> std::unique_ptr<std::istream, void(*)(std::istream*)> {
|
2022-11-24 12:10:08 -08:00
|
|
|
if (std::getenv("DOCTEST")) {
|
|
|
|
exit(doctest::Context{argc, argv}.run());
|
|
|
|
}
|
|
|
|
|
2022-11-07 21:00:14 -08:00
|
|
|
switch (argc) {
|
2022-11-21 18:49:22 -08:00
|
|
|
case 2:
|
2023-01-14 20:00:55 -08:00
|
|
|
return {new std::ifstream{argv[1]}, [](std::istream* p) { delete p; }};
|
2022-11-21 18:49:22 -08:00
|
|
|
case 1:
|
2023-01-14 20:00:55 -08:00
|
|
|
return {&std::cin, [](std::istream*){}};
|
2022-11-21 18:49:22 -08:00
|
|
|
default:
|
|
|
|
std::cerr << "bad arguments\n";
|
|
|
|
exit(EXIT_FAILURE);
|
2022-11-06 21:12:30 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|