From 9e165a8c2b205f37564e7e0e3e96c1fce52b6622 Mon Sep 17 00:00:00 2001 From: Jan Haller Date: Thu, 30 Jun 2022 13:55:15 +0200 Subject: [PATCH] Command line arguments '--version' and '--help' return exit code 0 instead of 255 Allows to detect whether those commands executed successfully, which makes integration with shell scripts/CI/bindings straightforward. (cherry picked from commit e3a8edf536ab8115594b0d6c3efa0603e71825ad) --- main/main.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/main/main.cpp b/main/main.cpp index f0734e2e839..13830937aab 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -478,6 +478,9 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph packed_data->add_pack_source(zip_packed_data); #endif + // Default exit code, can be modified for certain errors. + Error exit_code = ERR_INVALID_PARAMETER; + I = args.front(); while (I) { #ifdef OSX_ENABLED @@ -494,10 +497,12 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph if (I->get() == "-h" || I->get() == "--help" || I->get() == "/?") { // display help show_help = true; + exit_code = OK; goto error; } else if (I->get() == "--version") { print_line(get_full_version_string()); + exit_code = OK; goto error; } else if (I->get() == "-v" || I->get() == "--verbose") { // verbose output @@ -1328,7 +1333,7 @@ error: OS::get_singleton()->finalize_core(); locale = String(); - return ERR_INVALID_PARAMETER; + return exit_code; } Error Main::setup2(Thread::ID p_main_tid_override) {