Merge pull request #1677 from joakim-hove/version

Add special case handling of commandline argument "--version"
This commit is contained in:
Atgeirr Flø Rasmussen 2018-12-10 10:07:05 +01:00 committed by GitHub
commit eeb17b460f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 1 deletions

View File

@ -132,6 +132,13 @@ opm_add_test(flow
flow/flow_ebos_oilwater_polymer.cpp)
install(TARGETS flow DESTINATION bin)
add_test(NAME flow__version
COMMAND flow --version)
set_tests_properties(flow__version PROPERTIES
PASS_REGULAR_EXPRESSION "${${project}_LABEL}")
include(OpmBashCompletion)
opm_add_bash_completion(flow)

View File

@ -30,6 +30,7 @@
#include <opm/autodiff/SimulatorFullyImplicitBlackoilEbos.hpp>
#include <opm/autodiff/FlowMainEbos.hpp>
#include <opm/autodiff/moduleVersion.hpp>
#include <ewoms/common/propertysystem.hh>
#include <ewoms/common/parametersystem.hh>
#include <opm/autodiff/MissingFeatures.hpp>
@ -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);