diff --git a/main/main.cpp b/main/main.cpp index 13830937aab..37ef4332d2a 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -497,12 +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; + exit_code = ERR_HELP; // Hack to force an early exit in `main()` with a success code. goto error; } else if (I->get() == "--version") { print_line(get_full_version_string()); - exit_code = OK; + exit_code = ERR_HELP; // Hack to force an early exit in `main()` with a success code. goto error; } else if (I->get() == "-v" || I->get() == "--verbose") { // verbose output diff --git a/platform/android/java_godot_lib_jni.cpp b/platform/android/java_godot_lib_jni.cpp index ab688d4a8f6..89049beac88 100644 --- a/platform/android/java_godot_lib_jni.cpp +++ b/platform/android/java_godot_lib_jni.cpp @@ -199,6 +199,7 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_setup(JNIEnv *env, jc memfree(cmdline); } + // Note: --help and --version return ERR_HELP, but this should be translated to 0 if exit codes are propagated. if (err != OK) { return; // should exit instead and print the error } diff --git a/platform/iphone/godot_iphone.mm b/platform/iphone/godot_iphone.mm index 3c678b854c5..6cc2117c844 100644 --- a/platform/iphone/godot_iphone.mm +++ b/platform/iphone/godot_iphone.mm @@ -103,7 +103,10 @@ int iphone_main(int argc, char **argv, String data_dir, String cache_dir) { printf("os created\n"); Error err = Main::setup(fargv[0], argc - 1, &fargv[1], false); printf("setup %i\n", err); - if (err != OK) { + + if (err == ERR_HELP) { // Returned by --help and --version, so success. + return 0; + } else if (err != OK) { return 255; } diff --git a/platform/osx/godot_main_osx.mm b/platform/osx/godot_main_osx.mm index c9e21048011..43e3d67a319 100644 --- a/platform/osx/godot_main_osx.mm +++ b/platform/osx/godot_main_osx.mm @@ -64,8 +64,11 @@ int main(int argc, char **argv) { err = Main::setup(argv[0], argc - first_arg, &argv[first_arg]); } - if (err != OK) + if (err == ERR_HELP) { // Returned by --help and --version, so success. + return 0; + } else if (err != OK) { return 255; + } if (Main::start()) os.run(); // it is actually the OS that decides how to run diff --git a/platform/windows/godot_windows.cpp b/platform/windows/godot_windows.cpp index 2a6748201ef..ef70c33d54f 100644 --- a/platform/windows/godot_windows.cpp +++ b/platform/windows/godot_windows.cpp @@ -164,6 +164,10 @@ __declspec(dllexport) int widechar_main(int argc, wchar_t **argv) { delete[] argv_utf8[i]; } delete[] argv_utf8; + + if (err == ERR_HELP) { // Returned by --help and --version, so success. + return 0; + } return 255; } diff --git a/platform/x11/godot_x11.cpp b/platform/x11/godot_x11.cpp index ef7047372bf..62d230a4a91 100644 --- a/platform/x11/godot_x11.cpp +++ b/platform/x11/godot_x11.cpp @@ -48,6 +48,10 @@ int main(int argc, char *argv[]) { Error err = Main::setup(argv[0], argc - 1, &argv[1]); if (err != OK) { free(cwd); + + if (err == ERR_HELP) { // Returned by --help and --version, so success. + return 0; + } return 255; }