aocpp/lib/src/Startup.cpp

31 lines
564 B
C++
Raw Normal View History

#include <aocpp/Startup.hpp>
#include <cstdlib>
#include <iostream>
2022-11-07 21:00:14 -08:00
#include <optional>
#include <memory>
#include <fstream>
2022-11-13 11:42:40 -08:00
#include <utility>
#define DOCTEST_CONFIG_IMPLEMENT
#include <doctest.h>
namespace aocpp {
2022-11-07 21:00:14 -08:00
auto Startup(int argc, char ** argv) -> std::istream& {
2022-11-13 11:42:40 -08:00
if (std::getenv("DOCTEST")) {
exit(doctest::Context{argc, argv}.run());
}
2022-11-07 21:00:14 -08:00
static std::ifstream fin;
switch (argc) {
case 2: fin = std::ifstream{argv[1]}; return fin;
case 1: return std::cin;
default:
std::cerr << "bad arguments\n";
exit(EXIT_FAILURE);
}
}
}