From 8becbe15a2a7f229041b70d0333ffc96522efb6f Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Fri, 30 Sep 2016 16:49:30 -0700 Subject: [PATCH] Place check_and_get_package_spec in a separate file --- toolsrc/include/vcpkg_Input.h | 11 ++++++++++ toolsrc/include/vcpkg_cmd_arguments.h | 5 ----- toolsrc/src/commands_edit.cpp | 3 ++- toolsrc/src/commands_installation.cpp | 5 +++-- toolsrc/src/commands_remove.cpp | 3 ++- toolsrc/src/vcpkg_Input.cpp | 29 +++++++++++++++++++++++++++ toolsrc/src/vcpkg_cmd_arguments.cpp | 24 ---------------------- toolsrc/vcpkg/vcpkg.vcxproj | 2 ++ toolsrc/vcpkg/vcpkg.vcxproj.filters | 6 ++++++ 9 files changed, 55 insertions(+), 33 deletions(-) create mode 100644 toolsrc/include/vcpkg_Input.h create mode 100644 toolsrc/src/vcpkg_Input.cpp diff --git a/toolsrc/include/vcpkg_Input.h b/toolsrc/include/vcpkg_Input.h new file mode 100644 index 000000000..7041001c8 --- /dev/null +++ b/toolsrc/include/vcpkg_Input.h @@ -0,0 +1,11 @@ +#pragma once +#include +#include +#include "package_spec.h" + +namespace vcpkg {namespace Input +{ + package_spec check_and_get_package_spec(const std::string& package_spec_as_string, const triplet& default_target_triplet, const char* example_text); + + std::vector check_and_get_package_specs(const std::vector& package_specs_as_strings, const triplet& default_target_triplet, const char* example_text); +}} diff --git a/toolsrc/include/vcpkg_cmd_arguments.h b/toolsrc/include/vcpkg_cmd_arguments.h index 54b97cde1..95feb4814 100644 --- a/toolsrc/include/vcpkg_cmd_arguments.h +++ b/toolsrc/include/vcpkg_cmd_arguments.h @@ -4,9 +4,7 @@ #include #include #include "opt_bool.h" -#include "package_spec.h" #include "vcpkg_paths.h" -#include "StatusParagraphs.h" namespace vcpkg { @@ -15,9 +13,6 @@ namespace vcpkg static vcpkg_cmd_arguments create_from_command_line(const int argc, const wchar_t* const* const argv); static vcpkg_cmd_arguments create_from_arg_sequence(const std::string* arg_begin, const std::string* arg_end); - static package_spec check_and_get_package_spec(const std::string& package_spec_as_string, const triplet& default_target_triplet, const char* example_text); - static std::vector check_and_get_package_specs(const std::vector& package_specs_as_strings, const triplet& default_target_triplet, const char* example_text); - std::unique_ptr vcpkg_root_dir; std::unique_ptr target_triplet; opt_bool debug = opt_bool::unspecified; diff --git a/toolsrc/src/commands_edit.cpp b/toolsrc/src/commands_edit.cpp index 4973d6ef2..b17c02d5a 100644 --- a/toolsrc/src/commands_edit.cpp +++ b/toolsrc/src/commands_edit.cpp @@ -1,5 +1,6 @@ #include "vcpkg_Commands.h" #include "vcpkg_System.h" +#include "vcpkg_Input.h" namespace vcpkg { @@ -7,7 +8,7 @@ namespace vcpkg { static const std::string example = create_example_string("edit zlib"); args.check_exact_arg_count(1, example.c_str()); - const package_spec spec = vcpkg_cmd_arguments::check_and_get_package_spec(args.command_arguments.at(0), default_target_triplet, example.c_str()); + const package_spec spec = Input::check_and_get_package_spec(args.command_arguments.at(0), default_target_triplet, example.c_str()); // Find editor std::wstring env_EDITOR = System::wdupenv_str(L"EDITOR"); diff --git a/toolsrc/src/commands_installation.cpp b/toolsrc/src/commands_installation.cpp index 9eacfedcc..9eedebdbe 100644 --- a/toolsrc/src/commands_installation.cpp +++ b/toolsrc/src/commands_installation.cpp @@ -7,6 +7,7 @@ #include "post_build_lint.h" #include "vcpkg_System.h" #include "vcpkg_Dependencies.h" +#include "vcpkg_Input.h" namespace vcpkg { @@ -69,7 +70,7 @@ namespace vcpkg args.check_min_arg_count(1, example.c_str()); StatusParagraphs status_db = database_load_check(paths); - std::vector specs = vcpkg_cmd_arguments::check_and_get_package_specs(args.command_arguments, default_target_triplet, example.c_str()); + std::vector specs = Input::check_and_get_package_specs(args.command_arguments, default_target_triplet, example.c_str()); std::vector install_plan = Dependencies::create_dependency_ordered_install_plan(paths, specs, status_db); Checks::check_exit(!install_plan.empty(), "Install plan cannot be empty"); std::string specs_string = to_string(install_plan[0]); @@ -130,7 +131,7 @@ namespace vcpkg args.check_exact_arg_count(1, example.c_str()); StatusParagraphs status_db = database_load_check(paths); - const package_spec spec = vcpkg_cmd_arguments::check_and_get_package_spec(args.command_arguments.at(0), default_target_triplet, example.c_str()); + const package_spec spec = Input::check_and_get_package_spec(args.command_arguments.at(0), default_target_triplet, example.c_str()); std::unordered_set unmet_dependencies = Dependencies::find_unmet_dependencies(paths, spec, status_db); if (!unmet_dependencies.empty()) { diff --git a/toolsrc/src/commands_remove.cpp b/toolsrc/src/commands_remove.cpp index fd0c43de5..ebc000040 100644 --- a/toolsrc/src/commands_remove.cpp +++ b/toolsrc/src/commands_remove.cpp @@ -1,6 +1,7 @@ #include "vcpkg_Commands.h" #include "vcpkg.h" #include "vcpkg_System.h" +#include "vcpkg_Input.h" namespace vcpkg { @@ -28,7 +29,7 @@ namespace vcpkg const std::unordered_set options = args.check_and_get_optional_command_arguments({OPTION_PURGE}); auto status_db = database_load_check(paths); - std::vector specs = vcpkg_cmd_arguments::check_and_get_package_specs(args.command_arguments, default_target_triplet, example.c_str()); + std::vector specs = Input::check_and_get_package_specs(args.command_arguments, default_target_triplet, example.c_str()); bool alsoRemoveFolderFromPackages = options.find(OPTION_PURGE) != options.end(); for (const package_spec& spec : specs) diff --git a/toolsrc/src/vcpkg_Input.cpp b/toolsrc/src/vcpkg_Input.cpp new file mode 100644 index 000000000..de5890da1 --- /dev/null +++ b/toolsrc/src/vcpkg_Input.cpp @@ -0,0 +1,29 @@ +#include "vcpkg_Input.h" +#include "vcpkg_System.h" + +namespace vcpkg {namespace Input +{ + package_spec check_and_get_package_spec(const std::string& package_spec_as_string, const triplet& default_target_triplet, const char* example_text) + { + expected expected_spec = package_spec::from_string(package_spec_as_string, default_target_triplet); + if (auto spec = expected_spec.get()) + { + return *spec; + } + + System::println(System::color::error, "Error: %s: %s", expected_spec.error_code().message(), package_spec_as_string); + System::print(example_text); + exit(EXIT_FAILURE); + } + + std::vector check_and_get_package_specs(const std::vector& package_specs_as_strings, const triplet& default_target_triplet, const char* example_text) + { + std::vector specs; + for (const std::string& spec : package_specs_as_strings) + { + specs.push_back(check_and_get_package_spec(spec, default_target_triplet, example_text)); + } + + return specs; + } +}} diff --git a/toolsrc/src/vcpkg_cmd_arguments.cpp b/toolsrc/src/vcpkg_cmd_arguments.cpp index f1ab4e937..a286ba9b7 100644 --- a/toolsrc/src/vcpkg_cmd_arguments.cpp +++ b/toolsrc/src/vcpkg_cmd_arguments.cpp @@ -50,30 +50,6 @@ namespace vcpkg option_field = new_setting; } - package_spec vcpkg_cmd_arguments::check_and_get_package_spec(const std::string& package_spec_as_string, const triplet& default_target_triplet, const char* example_text) - { - expected expected_spec = package_spec::from_string(package_spec_as_string, default_target_triplet); - if (auto spec = expected_spec.get()) - { - return *spec; - } - - System::println(System::color::error, "Error: %s: %s", expected_spec.error_code().message(), package_spec_as_string); - System::print(example_text); - exit(EXIT_FAILURE); - } - - std::vector vcpkg_cmd_arguments::check_and_get_package_specs(const std::vector& package_specs_as_strings, const triplet& default_target_triplet, const char* example_text) - { - std::vector specs; - for (const std::string& spec : package_specs_as_strings) - { - specs.push_back(check_and_get_package_spec(spec, default_target_triplet, example_text)); - } - - return specs; - } - vcpkg_cmd_arguments vcpkg_cmd_arguments::create_from_command_line(const int argc, const wchar_t* const* const argv) { std::vector v; diff --git a/toolsrc/vcpkg/vcpkg.vcxproj b/toolsrc/vcpkg/vcpkg.vcxproj index a59683470..40c6f12cf 100644 --- a/toolsrc/vcpkg/vcpkg.vcxproj +++ b/toolsrc/vcpkg/vcpkg.vcxproj @@ -146,6 +146,7 @@ + @@ -153,6 +154,7 @@ + diff --git a/toolsrc/vcpkg/vcpkg.vcxproj.filters b/toolsrc/vcpkg/vcpkg.vcxproj.filters index 2e8a343fc..3b836ab3c 100644 --- a/toolsrc/vcpkg/vcpkg.vcxproj.filters +++ b/toolsrc/vcpkg/vcpkg.vcxproj.filters @@ -69,6 +69,9 @@ Source Files + + Source Files + @@ -86,5 +89,8 @@ Header Files + + Header Files + \ No newline at end of file