diff --git a/CMakeLists.txt b/CMakeLists.txt index e0e2b45..7711fae 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,26 @@ cmake_minimum_required(VERSION 3.16) project(endgame-analyzer CXX) +execute_process( + COMMAND git describe + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE GIT_DESCRIPTION + OUTPUT_STRIP_TRAILING_WHITESPACE +) + +execute_process( + COMMAND git -c log.showsignature=false log -1 --format=%h + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE GIT_COMMIT_HASH + OUTPUT_STRIP_TRAILING_WHITESPACE +) + +configure_file( + ${CMAKE_SOURCE_DIR}/include/version.h.in + ${CMAKE_BINARY_DIR}/generated/version.h +) +include_directories(${CMAKE_BINARY_DIR}/generated) + set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wpedantic -Werror") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3") diff --git a/include/command_line_interface.h b/include/command_line_interface.h index b5b2d71..835a574 100644 --- a/include/command_line_interface.h +++ b/include/command_line_interface.h @@ -72,6 +72,11 @@ namespace Hanabi * and future game states, including suboptimal ones. */ bool list_actions{false}; + + /** + * If true, prints version information of the program and exits immediately. + */ + bool version_info{false}; }; /** diff --git a/src/command_line_interface.cpp b/src/command_line_interface.cpp index 261a368..5d3f9d2 100644 --- a/src/command_line_interface.cpp +++ b/src/command_line_interface.cpp @@ -4,6 +4,8 @@ #include "null_buffer.h" #include "state_explorer.h" +#include + #include "command_line_interface.h" #include "myassert.h" @@ -36,6 +38,10 @@ namespace Hanabi int run_cli(CLIParms const & parms) { + if (parms.version_info) { + std::cout << "endgame-analyzer " << VERSION_GIT_DESCRIPTION << " (commit " << VERSION_GIT_COMMIT_HASH << ")"; + return EXIT_SUCCESS; + } // We want to do this sanity check here again, // so that the run_cli method itself can ensure that arguments are fully valid // and we cannot run into crashes due to bad specified parameters @@ -246,12 +252,19 @@ namespace Hanabi ("list-actions,l","List all actions (including suboptimal ones) of all turns after specified state.") ("all-clues", "Whenever evaluating a game state, evaluate it with all clue counts and output their " "probabilities.") - ("quiet,q", "Deactivate all non-essential prints. Useful if output is parsed by another program."); + ("quiet,q", "Deactivate all non-essential prints. Useful if output is parsed by another program.") + ("version,v", "Print version information and exit."); bpo::variables_map vm; bpo::store(bpo::parse_command_line(argc, argv, desc), vm); bpo::notify(vm); + if (vm.count("version")) + { + parms.version_info = true; + return parms; + } + if (vm.count("help")) { std::cout << "This program performs endgame analysis of Hanabi. It calculates optimum strategies\n"