From d0ecd1e3fdee04d24ba00247b494f7275808ef9b Mon Sep 17 00:00:00 2001 From: Jochen Topf Date: Thu, 20 Jun 2024 14:25:58 +0200 Subject: [PATCH] Add option -e, --exit-ignore-warnings Return with exit code 0 even if there are warnings. Makes use in scripts simpler. --- man/osmcoastline.md | 5 ++++- src/options.cpp | 7 ++++++- src/options.hpp | 3 +++ src/osmcoastline.cpp | 2 +- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/man/osmcoastline.md b/man/osmcoastline.md index 5e9b938..2b5230c 100644 --- a/man/osmcoastline.md +++ b/man/osmcoastline.md @@ -46,6 +46,9 @@ description of the options below and the README.md for details. -d, \--debug : Enable debugging output. +-e, \--exit-ignore-warnings +: Return with exit code 0 even if there are warnings. + -f, \--overwrite : Overwrite output file if it already exists. @@ -114,7 +117,7 @@ program first. See its man page for details. ~ if everything was okay 1 - ~ if there were warnings while processing the coastline + ~ if there were warnings while processing the coastline (unless -e is set) 2 ~ if there were errors while processing the coastline diff --git a/src/options.cpp b/src/options.cpp index c40fe86..a4a4d84 100644 --- a/src/options.cpp +++ b/src/options.cpp @@ -44,6 +44,7 @@ static void print_help() { << " -b, --bbox-overlap=OVERLAP - Set overlap when splitting polygons\n" << " -i, --no-index - Do not create spatial indexes in output db\n" << " -d, --debug - Enable debugging output\n" + << " -e, --exit-ignore-warnings - Exit with code 0 even if there are warnings\n" << " -f, --overwrite - Overwrite output file if it already exists\n" << " -g, --gdal-driver=DRIVER - GDAL driver (SQLite or ESRI Shapefile)\n" << " -l, --output-lines - Output coastlines as lines to database file\n" @@ -99,6 +100,7 @@ int Options::parse(int argc, char* argv[]) { {"close-distance", required_argument, nullptr, 'c'}, {"no-index", no_argument, nullptr, 'i'}, {"debug", no_argument, nullptr, 'd'}, + {"exit-ignore-warnings", no_argument, nullptr, 'e'}, {"gdal-driver", required_argument, nullptr, 'g'}, {"help", no_argument, nullptr, 'h'}, {"output-lines", no_argument, nullptr, 'l'}, @@ -115,7 +117,7 @@ int Options::parse(int argc, char* argv[]) { }; while (true) { - const int c = getopt_long(argc, argv, "b:c:idg:hlm:o:p:rfs:S:vV", long_options, nullptr); + const int c = getopt_long(argc, argv, "b:c:ideg:hlm:o:p:rfs:S:vV", long_options, nullptr); if (c == -1) { break; } @@ -134,6 +136,9 @@ int Options::parse(int argc, char* argv[]) { debug = true; std::cerr << "Enabled debug option\n"; break; + case 'e': + exit_ignore_warnings = true; + break; case 'h': print_help(); return return_code_ok; diff --git a/src/options.hpp b/src/options.hpp index 3228724..a516419 100644 --- a/src/options.hpp +++ b/src/options.hpp @@ -90,6 +90,9 @@ struct Options { /// Verbose output? bool verbose = false; + /// Exit program with code 0 even if there are warnings? + bool exit_ignore_warnings = false; + /// Name of optional segment file std::string segmentfile; diff --git a/src/osmcoastline.cpp b/src/osmcoastline.cpp index bb226fe..b7d0e13 100644 --- a/src/osmcoastline.cpp +++ b/src/osmcoastline.cpp @@ -426,7 +426,7 @@ int main(int argc, char *argv[]) { return return_code_error; } - if (warnings) { + if (warnings && !options.exit_ignore_warnings) { return return_code_warning; }