aocpp/lib/src/Startup.cpp

32 lines
652 B
C++

#include <aocpp/Startup.hpp>
#include <cstdlib>
#include <iostream>
#include <optional>
#include <memory>
#include <fstream>
#include <utility>
#define DOCTEST_CONFIG_IMPLEMENT
#include <doctest.h>
namespace aocpp {
auto Startup(int argc, char ** argv) -> std::unique_ptr<std::istream, void(*)(std::istream*)> {
if (std::getenv("DOCTEST")) {
exit(doctest::Context{argc, argv}.run());
}
switch (argc) {
case 2:
return {new std::ifstream{argv[1]}, [](std::istream* p) { delete p; }};
case 1:
return {&std::cin, [](std::istream*){}};
default:
std::cerr << "bad arguments\n";
exit(EXIT_FAILURE);
}
}
}