better cli interface: support both files and ids

This commit is contained in:
Maximilian Keßler 2023-08-08 11:08:58 +02:00
parent d7f7d3eb6d
commit bfe2b85dec
Signed by: max
GPG key ID: BCC5A619923C0BA5

View file

@ -14,7 +14,7 @@
namespace Hanabi {
void download(int game_id, int turn) {
void download(std::variant<int, const char*> game_id, int turn) {
auto game = Download::get_game(game_id, turn);
std::cout << "Analysing state: " << std::endl << *game << std::endl;
auto res = game->backtrack(1);
@ -109,11 +109,15 @@ int main(int argc, char *argv[]) {
#ifndef NDEBUG
test();
#endif
check_games(4, 9);
check_games(2, 9);
if(argc == 3) {
std::string game(argv[1]);
std::string turn (argv[2]);
try {
Hanabi::download(std::stoi(game), std::stoi(turn));
} catch(std::invalid_argument&) {
Hanabi::download(game.c_str(), std::stoi(turn));
}
} else {
Hanabi::print_usage(argv[0]);
}