From bfe2b85decf9072153ce67dbd1d8cd981b7f228d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Tue, 8 Aug 2023 11:08:58 +0200 Subject: [PATCH] better cli interface: support both files and ids --- main.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/main.cpp b/main.cpp index 98630b0..e5e6f69 100644 --- a/main.cpp +++ b/main.cpp @@ -14,7 +14,7 @@ namespace Hanabi { - void download(int game_id, int turn) { + void download(std::variant 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 game(argv[1]); std::string turn (argv[2]); - Hanabi::download(std::stoi(game), std::stoi(turn)); + 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]); }