Place check_and_get_package_spec in a separate file

This commit is contained in:
Alexander Karatarakis 2016-09-30 16:49:30 -07:00
Родитель bcb2be360a
Коммит 8becbe15a2
9 изменённых файлов: 55 добавлений и 33 удалений

Просмотреть файл

@ -0,0 +1,11 @@
#pragma once
#include <vector>
#include <string>
#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<package_spec> check_and_get_package_specs(const std::vector<std::string>& package_specs_as_strings, const triplet& default_target_triplet, const char* example_text);
}}

Просмотреть файл

@ -4,9 +4,7 @@
#include <vector>
#include <unordered_set>
#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<package_spec> check_and_get_package_specs(const std::vector<std::string>& package_specs_as_strings, const triplet& default_target_triplet, const char* example_text);
std::unique_ptr<std::string> vcpkg_root_dir;
std::unique_ptr<std::string> target_triplet;
opt_bool debug = opt_bool::unspecified;

Просмотреть файл

@ -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");

Просмотреть файл

@ -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<package_spec> specs = vcpkg_cmd_arguments::check_and_get_package_specs(args.command_arguments, default_target_triplet, example.c_str());
std::vector<package_spec> specs = Input::check_and_get_package_specs(args.command_arguments, default_target_triplet, example.c_str());
std::vector<package_spec> 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<package_spec> unmet_dependencies = Dependencies::find_unmet_dependencies(paths, spec, status_db);
if (!unmet_dependencies.empty())
{

Просмотреть файл

@ -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<std::string> options = args.check_and_get_optional_command_arguments({OPTION_PURGE});
auto status_db = database_load_check(paths);
std::vector<package_spec> specs = vcpkg_cmd_arguments::check_and_get_package_specs(args.command_arguments, default_target_triplet, example.c_str());
std::vector<package_spec> 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)

Просмотреть файл

@ -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<package_spec> 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<package_spec> check_and_get_package_specs(const std::vector<std::string>& package_specs_as_strings, const triplet& default_target_triplet, const char* example_text)
{
std::vector<package_spec> 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;
}
}}

Просмотреть файл

@ -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<package_spec> 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<package_spec> vcpkg_cmd_arguments::check_and_get_package_specs(const std::vector<std::string>& package_specs_as_strings, const triplet& default_target_triplet, const char* example_text)
{
std::vector<package_spec> 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<std::string> v;

Просмотреть файл

@ -146,6 +146,7 @@
<ClCompile Include="..\src\main.cpp" />
<ClCompile Include="..\src\commands_help.cpp" />
<ClCompile Include="..\src\post_build_lint.cpp" />
<ClCompile Include="..\src\vcpkg_Input.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\include\vcpkg_cmd_arguments.h" />
@ -153,6 +154,7 @@
<ClInclude Include="..\include\vcpkg_Dependencies.h" />
<ClInclude Include="..\include\vcpkg_Environment.h" />
<ClInclude Include="..\include\post_build_lint.h" />
<ClInclude Include="..\include\vcpkg_Input.h" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\vcpkgcommon\vcpkgcommon.vcxproj">

Просмотреть файл

@ -69,6 +69,9 @@
<ClCompile Include="..\src\vcpkg_Dependencies.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\src\vcpkg_Input.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\include\post_build_lint.h">
@ -86,5 +89,8 @@
<ClInclude Include="..\include\vcpkg_Dependencies.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\include\vcpkg_Input.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>