From 54417a80333e2439ad9c1b2b9acc0c9b24495f2f Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Sun, 9 Dec 2018 20:47:00 +0100 Subject: [PATCH] Intercept and the handle commandline argument --version --- flow/flow.cpp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/flow/flow.cpp b/flow/flow.cpp index bdbf08334..ff2afb0b8 100644 --- a/flow/flow.cpp +++ b/flow/flow.cpp @@ -30,6 +30,7 @@ #include #include +#include #include #include #include @@ -83,12 +84,31 @@ namespace detail throw std::invalid_argument( "Cannot find input case " + casename ); } -} + // This function is an extreme special case, if the program has been invoked + // *exactly* as: + // + // flow --version + // + // the call is intercepted by this function which will print "flow $version" + // on stdout and exit(0). + void handleVersionCmdLine(int argc, char** argv) { + if (argc != 2) + return; + + if (std::strcmp(argv[1], "--version") == 0) { + std::cout << "flow " << Opm::moduleVersionName() << std::endl; + std::exit(EXIT_SUCCESS); + } + } + +} + // ----------------- Main program ----------------- int main(int argc, char** argv) { + detail::handleVersionCmdLine(argc, argv); // MPI setup. #if HAVE_DUNE_FEM Dune::Fem::MPIManager::initialize(argc, argv);