From 4bc91f1f269aa72dccd51a8f07134e4e66701793 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Wed, 22 Mar 2017 17:45:39 -0700 Subject: [PATCH] [commands] Use Checks::exit_fail/success/with_code() --- toolsrc/src/commands_build.cpp | 13 +++++-------- toolsrc/src/commands_cache.cpp | 4 ++-- toolsrc/src/commands_ci.cpp | 2 +- toolsrc/src/commands_contact.cpp | 2 +- toolsrc/src/commands_create.cpp | 2 +- toolsrc/src/commands_edit.cpp | 2 +- toolsrc/src/commands_hash.cpp | 2 +- toolsrc/src/commands_help.cpp | 6 +++--- toolsrc/src/commands_import.cpp | 2 +- toolsrc/src/commands_install.cpp | 8 ++++---- toolsrc/src/commands_integrate.cpp | 12 ++++++------ toolsrc/src/commands_list.cpp | 4 ++-- toolsrc/src/commands_owns.cpp | 2 +- toolsrc/src/commands_portsdiff.cpp | 2 +- toolsrc/src/commands_remove.cpp | 4 ++-- toolsrc/src/commands_search.cpp | 4 ++-- toolsrc/src/commands_update.cpp | 2 +- toolsrc/src/commands_version.cpp | 2 +- 18 files changed, 36 insertions(+), 39 deletions(-) diff --git a/toolsrc/src/commands_build.cpp b/toolsrc/src/commands_build.cpp index 8e73dde3b6..390a117dd4 100644 --- a/toolsrc/src/commands_build.cpp +++ b/toolsrc/src/commands_build.cpp @@ -126,11 +126,8 @@ namespace vcpkg::Commands::Build if (options.find(OPTION_CHECKS_ONLY) != options.end()) { const size_t error_count = PostBuildLint::perform_all_checks(spec, paths); - if (error_count > 0) - { - exit(EXIT_FAILURE); - } - exit(EXIT_SUCCESS); + Checks::check_exit(VCPKG_LINE_INFO, error_count == 0); + Checks::exit_success(VCPKG_LINE_INFO); } const expected maybe_spgh = Paragraphs::try_load_port(port_dir); @@ -158,17 +155,17 @@ namespace vcpkg::Commands::Build System::println(" %s", p.spec.toString()); } System::println(""); - exit(EXIT_FAILURE); + Checks::exit_fail(VCPKG_LINE_INFO); } if (result != BuildResult::SUCCEEDED) { System::println(System::color::error, Build::create_error_message(result, spec)); System::println(Build::create_user_troubleshooting_message(spec)); - exit(EXIT_FAILURE); + Checks::exit_fail(VCPKG_LINE_INFO); } - exit(EXIT_SUCCESS); + Checks::exit_success(VCPKG_LINE_INFO); } void perform_and_exit(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths, const triplet& default_target_triplet) diff --git a/toolsrc/src/commands_cache.cpp b/toolsrc/src/commands_cache.cpp index e255b5dff7..417799abb6 100644 --- a/toolsrc/src/commands_cache.cpp +++ b/toolsrc/src/commands_cache.cpp @@ -46,7 +46,7 @@ namespace vcpkg::Commands::Cache if (binary_paragraphs.empty()) { System::println("No packages are cached."); - exit(EXIT_SUCCESS); + Checks::exit_success(VCPKG_LINE_INFO); } if (args.command_arguments.size() == 0) @@ -72,6 +72,6 @@ namespace vcpkg::Commands::Cache } } - exit(EXIT_SUCCESS); + Checks::exit_success(VCPKG_LINE_INFO); } } diff --git a/toolsrc/src/commands_ci.cpp b/toolsrc/src/commands_ci.cpp index 45ef2db281..ef55d24450 100644 --- a/toolsrc/src/commands_ci.cpp +++ b/toolsrc/src/commands_ci.cpp @@ -115,6 +115,6 @@ namespace vcpkg::Commands::CI System::println(" %s: %d", Build::to_string(entry.first), entry.second); } - exit(EXIT_SUCCESS); + Checks::exit_success(VCPKG_LINE_INFO); } } diff --git a/toolsrc/src/commands_contact.cpp b/toolsrc/src/commands_contact.cpp index 29f0d4d274..fe65a9e334 100644 --- a/toolsrc/src/commands_contact.cpp +++ b/toolsrc/src/commands_contact.cpp @@ -16,6 +16,6 @@ namespace vcpkg::Commands::Contact args.check_and_get_optional_command_arguments({}); System::println("Send an email to %s with any feedback.", email()); - exit(EXIT_SUCCESS); + Checks::exit_success(VCPKG_LINE_INFO); } } diff --git a/toolsrc/src/commands_create.cpp b/toolsrc/src/commands_create.cpp index 2c3e028779..23fac3f9d0 100644 --- a/toolsrc/src/commands_create.cpp +++ b/toolsrc/src/commands_create.cpp @@ -36,6 +36,6 @@ namespace vcpkg::Commands::Create } const std::wstring cmd_launch_cmake = make_cmake_cmd(cmake_exe, paths.ports_cmake, cmake_args); - exit(System::cmd_execute_clean(cmd_launch_cmake)); + Checks::exit_with_code(VCPKG_LINE_INFO, System::cmd_execute_clean(cmd_launch_cmake)); } } diff --git a/toolsrc/src/commands_edit.cpp b/toolsrc/src/commands_edit.cpp index 1252790af5..d9cd627d26 100644 --- a/toolsrc/src/commands_edit.cpp +++ b/toolsrc/src/commands_edit.cpp @@ -72,6 +72,6 @@ namespace vcpkg::Commands::Edit } std::wstring cmdLine = Strings::wformat(LR"("%s" "%s" "%s" -n)", env_EDITOR, portpath.native(), (portpath / "portfile.cmake").native()); - exit(System::cmd_execute(cmdLine)); + Checks::exit_with_code(VCPKG_LINE_INFO, System::cmd_execute(cmdLine)); } } diff --git a/toolsrc/src/commands_hash.cpp b/toolsrc/src/commands_hash.cpp index 2e55a4bb68..ea69770700 100644 --- a/toolsrc/src/commands_hash.cpp +++ b/toolsrc/src/commands_hash.cpp @@ -41,6 +41,6 @@ namespace vcpkg::Commands::Hash do_file_hash(args.command_arguments[0], Strings::utf8_to_utf16(args.command_arguments[1])); } - exit(EXIT_SUCCESS); + Checks::exit_success(VCPKG_LINE_INFO); } } diff --git a/toolsrc/src/commands_help.cpp b/toolsrc/src/commands_help.cpp index 49b5697c32..f5cde9435a 100644 --- a/toolsrc/src/commands_help.cpp +++ b/toolsrc/src/commands_help.cpp @@ -72,7 +72,7 @@ namespace vcpkg::Commands::Help if (args.command_arguments.empty()) { print_usage(); - exit(EXIT_SUCCESS); + Checks::exit_success(VCPKG_LINE_INFO); } const auto& topic = args.command_arguments[0]; if (topic == "triplet") @@ -83,8 +83,8 @@ namespace vcpkg::Commands::Help { System::println(System::color::error, "Error: unknown topic %s", topic); print_usage(); - exit(EXIT_FAILURE); + Checks::exit_fail(VCPKG_LINE_INFO); } - exit(EXIT_SUCCESS); + Checks::exit_success(VCPKG_LINE_INFO); } } diff --git a/toolsrc/src/commands_import.cpp b/toolsrc/src/commands_import.cpp index a74b9e6629..69710765f7 100644 --- a/toolsrc/src/commands_import.cpp +++ b/toolsrc/src/commands_import.cpp @@ -80,6 +80,6 @@ namespace vcpkg::Commands::Import auto& control_file_data = spgh.package; do_import(paths, include_directory, project_directory, control_file_data); - exit(EXIT_SUCCESS); + Checks::exit_success(VCPKG_LINE_INFO); } } diff --git a/toolsrc/src/commands_install.cpp b/toolsrc/src/commands_install.cpp index b7a8eafacf..3ca4d5dbba 100644 --- a/toolsrc/src/commands_install.cpp +++ b/toolsrc/src/commands_install.cpp @@ -159,7 +159,7 @@ namespace vcpkg::Commands::Install System::print("\n "); System::println(Strings::join("\n ", intersection)); System::println(""); - exit(EXIT_FAILURE); + Checks::exit_fail(VCPKG_LINE_INFO); } StatusParagraph spgh; @@ -221,7 +221,7 @@ namespace vcpkg::Commands::Install { System::println(System::color::error, Build::create_error_message(result, action.spec)); System::println(Build::create_user_troubleshooting_message(action.spec)); - exit(EXIT_FAILURE); + Checks::exit_fail(VCPKG_LINE_INFO); } const BinaryParagraph bpgh = Paragraphs::try_load_cached_package(paths, action.spec).get_or_throw(VCPKG_LINE_INFO); install_package(paths, bpgh, &status_db); @@ -238,10 +238,10 @@ namespace vcpkg::Commands::Install catch (const std::exception& e) { System::println(System::color::error, "Error: Could not install package %s: %s", action.spec, e.what()); - exit(EXIT_FAILURE); + Checks::exit_fail(VCPKG_LINE_INFO); } } - exit(EXIT_SUCCESS); + Checks::exit_success(VCPKG_LINE_INFO); } } diff --git a/toolsrc/src/commands_integrate.cpp b/toolsrc/src/commands_integrate.cpp index 8e23a3dcf8..b72a7a483d 100644 --- a/toolsrc/src/commands_integrate.cpp +++ b/toolsrc/src/commands_integrate.cpp @@ -154,7 +154,7 @@ namespace vcpkg::Commands::Integrate break; case elevation_prompt_user_choice::no: System::println(System::color::warning, "Warning: Previous integration file was not removed"); - exit(EXIT_FAILURE); + Checks::exit_fail(VCPKG_LINE_INFO); default: Checks::unreachable(VCPKG_LINE_INFO); } @@ -193,7 +193,7 @@ namespace vcpkg::Commands::Integrate break; case elevation_prompt_user_choice::no: System::println(System::color::warning, "Warning: integration was not applied"); - exit(EXIT_FAILURE); + Checks::exit_fail(VCPKG_LINE_INFO); default: Checks::unreachable(VCPKG_LINE_INFO); } @@ -208,7 +208,7 @@ namespace vcpkg::Commands::Integrate if (!fs::copy_file(appdata_src_path, appdata_dst_path, fs::copy_options::overwrite_existing)) { System::println(System::color::error, "Error: Failed to copy file: %s -> %s", appdata_src_path.string(), appdata_dst_path.string()); - exit(EXIT_FAILURE); + Checks::exit_fail(VCPKG_LINE_INFO); } System::println(System::color::success, "Applied user-wide integration for this vcpkg root."); const fs::path cmake_toolchain = paths.buildsystems / "vcpkg.cmake"; @@ -219,7 +219,7 @@ namespace vcpkg::Commands::Integrate "\n" "CMake projects should use -DCMAKE_TOOLCHAIN_FILE=%s", cmake_toolchain.generic_string()); - exit(EXIT_SUCCESS); + Checks::exit_success(VCPKG_LINE_INFO); } static void integrate_remove() @@ -240,7 +240,7 @@ namespace vcpkg::Commands::Integrate System::println(System::color::success, "User-wide integration is not installed"); } - exit(EXIT_SUCCESS); + Checks::exit_success(VCPKG_LINE_INFO); } static void integrate_project(const vcpkg_paths& paths) @@ -276,7 +276,7 @@ With a project open, go to Tools->NuGet Package Manager->Package Manager Console Install-Package %s -Source "%s" )", nuget_id, buildsystems_dir.generic_string()); - exit(EXIT_SUCCESS); + Checks::exit_success(VCPKG_LINE_INFO); } const char* const INTEGRATE_COMMAND_HELPSTRING = diff --git a/toolsrc/src/commands_list.cpp b/toolsrc/src/commands_list.cpp index 7bfc11f1b0..cee95767bf 100644 --- a/toolsrc/src/commands_list.cpp +++ b/toolsrc/src/commands_list.cpp @@ -33,7 +33,7 @@ namespace vcpkg::Commands::List if (installed_packages.empty()) { System::println("No packages are installed. Did you mean `search`?"); - exit(EXIT_SUCCESS); + Checks::exit_success(VCPKG_LINE_INFO); } std::sort(installed_packages.begin(), installed_packages.end(), @@ -64,6 +64,6 @@ namespace vcpkg::Commands::List } } - exit(EXIT_SUCCESS); + Checks::exit_success(VCPKG_LINE_INFO); } } diff --git a/toolsrc/src/commands_owns.cpp b/toolsrc/src/commands_owns.cpp index 16bb986e2f..83c696fa9d 100644 --- a/toolsrc/src/commands_owns.cpp +++ b/toolsrc/src/commands_owns.cpp @@ -30,6 +30,6 @@ namespace vcpkg::Commands::Owns StatusParagraphs status_db = database_load_check(paths); search_file(paths, args.command_arguments[0], status_db); - exit(EXIT_SUCCESS); + Checks::exit_success(VCPKG_LINE_INFO); } } diff --git a/toolsrc/src/commands_portsdiff.cpp b/toolsrc/src/commands_portsdiff.cpp index b1a166ed1d..d41ebb9fba 100644 --- a/toolsrc/src/commands_portsdiff.cpp +++ b/toolsrc/src/commands_portsdiff.cpp @@ -133,6 +133,6 @@ namespace vcpkg::Commands::PortsDiff System::println("There were no changes in the ports between the two commits."); } - exit(EXIT_SUCCESS); + Checks::exit_success(VCPKG_LINE_INFO); } } diff --git a/toolsrc/src/commands_remove.cpp b/toolsrc/src/commands_remove.cpp index 7e4228496b..e6677d7408 100644 --- a/toolsrc/src/commands_remove.cpp +++ b/toolsrc/src/commands_remove.cpp @@ -189,7 +189,7 @@ namespace vcpkg::Commands::Remove System::println(System::color::warning, "Additional packages (*) need to be removed to complete this operation.\n" "If you are sure you want to remove them, run the command with the --recurse option"); - exit(EXIT_FAILURE); + Checks::exit_fail(VCPKG_LINE_INFO); } for (const package_spec_with_remove_plan& action : remove_plan) @@ -219,6 +219,6 @@ namespace vcpkg::Commands::Remove } } - exit(EXIT_SUCCESS); + Checks::exit_success(VCPKG_LINE_INFO); } } diff --git a/toolsrc/src/commands_search.cpp b/toolsrc/src/commands_search.cpp index 463257fc9d..93b48da632 100644 --- a/toolsrc/src/commands_search.cpp +++ b/toolsrc/src/commands_search.cpp @@ -64,7 +64,7 @@ namespace vcpkg::Commands::Search { const std::string graph_as_string = create_graph_as_string(source_paragraphs); System::println(graph_as_string); - exit(EXIT_SUCCESS); + Checks::exit_success(VCPKG_LINE_INFO); } if (args.command_arguments.empty()) @@ -91,6 +91,6 @@ namespace vcpkg::Commands::Search System::println("\nIf your library is not listed, please open an issue at and/or consider making a pull request:\n" " https://github.com/Microsoft/vcpkg/issues"); - exit(EXIT_SUCCESS); + Checks::exit_success(VCPKG_LINE_INFO); } } diff --git a/toolsrc/src/commands_update.cpp b/toolsrc/src/commands_update.cpp index 8131d9a73c..57ee7b6166 100644 --- a/toolsrc/src/commands_update.cpp +++ b/toolsrc/src/commands_update.cpp @@ -75,6 +75,6 @@ namespace vcpkg::Commands::Update } } - exit(EXIT_SUCCESS); + Checks::exit_success(VCPKG_LINE_INFO); } } diff --git a/toolsrc/src/commands_version.cpp b/toolsrc/src/commands_version.cpp index 4789e2409c..7e8b4d1cb2 100644 --- a/toolsrc/src/commands_version.cpp +++ b/toolsrc/src/commands_version.cpp @@ -32,6 +32,6 @@ namespace vcpkg::Commands::Version "\n" "See LICENSE.txt for license information.", version() ); - exit(EXIT_SUCCESS); + Checks::exit_success(VCPKG_LINE_INFO); } }