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 { 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); auto game = Download::get_game(game_id, turn);
std::cout << "Analysing state: " << std::endl << *game << std::endl; std::cout << "Analysing state: " << std::endl << *game << std::endl;
auto res = game->backtrack(1); auto res = game->backtrack(1);
@ -109,11 +109,15 @@ int main(int argc, char *argv[]) {
#ifndef NDEBUG #ifndef NDEBUG
test(); test();
#endif #endif
check_games(4, 9); check_games(2, 9);
if(argc == 3) { if(argc == 3) {
std::string game (argv[1]); std::string game(argv[1]);
std::string turn (argv[2]); 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 { } else {
Hanabi::print_usage(argv[0]); Hanabi::print_usage(argv[0]);
} }