Use Algorithm to Locate '--version' Option

This commit is contained in:
Bård Skaflestad 2021-10-07 15:20:36 +02:00
parent fca167acfd
commit ad74de2e1a

View File

@ -509,13 +509,17 @@ namespace Opm
// //
// the call is intercepted by this function which will print "flow $version" // the call is intercepted by this function which will print "flow $version"
// on stdout and exit(0). // on stdout and exit(0).
void handleVersionCmdLine_(int argc, char** argv) { void handleVersionCmdLine_(int argc, char** argv)
for ( int i = 1; i < argc; ++i ) {
auto pos = std::find_if(argv, argv + argc,
[](const char* arg)
{ {
if (std::strcmp(argv[i], "--version") == 0) { return std::strcmp(arg, "--version") == 0;
std::cout << "flow " << moduleVersionName() << std::endl; });
std::exit(EXIT_SUCCESS);
} if (pos != argv + argc) {
std::cout << "flow " << moduleVersionName() << std::endl;
std::exit(EXIT_SUCCESS);
} }
} }