aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/src/commands_install.cpp
diff options
context:
space:
mode:
authorAlexander Karatarakis <alkarata@microsoft.com>2017-04-14 14:31:34 -0700
committerAlexander Karatarakis <alkarata@microsoft.com>2017-04-14 14:31:45 -0700
commitaeaccc781440b7dc62b41d5449a0e5c720928295 (patch)
tree87c95b195187ad1a52a4c930af6be7672ba28cdf /toolsrc/src/commands_install.cpp
parent55f554eea1c1c5135329ae18ab4f50661ba7c6bf (diff)
downloadvcpkg-aeaccc781440b7dc62b41d5449a0e5c720928295.tar.gz
vcpkg-aeaccc781440b7dc62b41d5449a0e5c720928295.zip
Rework print_plan() for `remove` and `install`
Diffstat (limited to 'toolsrc/src/commands_install.cpp')
-rw-r--r--toolsrc/src/commands_install.cpp64
1 files changed, 29 insertions, 35 deletions
diff --git a/toolsrc/src/commands_install.cpp b/toolsrc/src/commands_install.cpp
index 55b7aaf64..a02137e40 100644
--- a/toolsrc/src/commands_install.cpp
+++ b/toolsrc/src/commands_install.cpp
@@ -140,47 +140,41 @@ namespace vcpkg::Commands::Install
static void print_plan(const std::vector<InstallPlanAction>& plan)
{
- std::vector<const InstallPlanAction*> already_installed;
- std::vector<const InstallPlanAction*> build_and_install;
- std::vector<const InstallPlanAction*> install;
+ static constexpr std::array<InstallPlanType, 3> order = { InstallPlanType::ALREADY_INSTALLED, InstallPlanType::BUILD_AND_INSTALL, InstallPlanType::INSTALL };
- for (const InstallPlanAction& i : plan)
+ std::map<InstallPlanType, std::vector<const InstallPlanAction*>> group_by_plan_type;
+ Util::group_by(plan, &group_by_plan_type, [](const InstallPlanAction& p) { return p.plan_type; });
+
+ for (const InstallPlanType plan_type : order)
{
- switch (i.plan_type)
+ auto it = group_by_plan_type.find(plan_type);
+ if (it == group_by_plan_type.cend())
+ {
+ continue;
+ }
+
+ std::vector<const InstallPlanAction*> cont = it->second;
+ std::sort(cont.begin(), cont.end(), &InstallPlanAction::compare_by_name);
+ const std::string as_string = Strings::join("\n", cont, [](const InstallPlanAction* p)
+ {
+ return Dependencies::to_output_string(p->request_type, p->spec.to_string());
+ });
+
+ switch (plan_type)
{
case InstallPlanType::ALREADY_INSTALLED:
- already_installed.push_back(&i);
+ System::println("The following packages are already installed:\n%s", as_string);
continue;
case InstallPlanType::BUILD_AND_INSTALL:
- build_and_install.push_back(&i);
+ System::println("The following packages will be built and installed:\n%s", as_string);
continue;
case InstallPlanType::INSTALL:
- install.push_back(&i);
+ System::println("The following packages will be installed:\n%s", as_string);
continue;
default:
Checks::unreachable(VCPKG_LINE_INFO);
}
}
-
- auto print_lambda = [](const InstallPlanAction* p) { return Dependencies::to_output_string(p->request_type, p->spec.to_string()); };
-
- if (!already_installed.empty())
- {
- std::sort(already_installed.begin(), already_installed.end(), &InstallPlanAction::compare_by_name);
- System::println("The following packages are already installed:\n%s", Strings::join("\n", already_installed, print_lambda));
- }
-
- if (!build_and_install.empty())
- {
- std::sort(build_and_install.begin(), build_and_install.end(), &InstallPlanAction::compare_by_name);
- System::println("The following packages will be built and installed:\n%s", Strings::join("\n", build_and_install, print_lambda));
- }
-
- if (!install.empty())
- {
- std::sort(install.begin(), install.end(), &InstallPlanAction::compare_by_name);
- System::println("The following packages will be installed:\n%s", Strings::join("\n", install, print_lambda));
- }
}
void install_package(const VcpkgPaths& paths, const BinaryParagraph& binary_paragraph, StatusParagraphs* status_db)
@@ -239,9 +233,9 @@ namespace vcpkg::Commands::Install
args.check_min_arg_count(1, example);
const std::vector<PackageSpec> specs = Util::fmap(args.command_arguments, [&](auto&& arg)
- {
- return Input::check_and_get_package_spec(arg, default_triplet, example);
- });
+ {
+ return Input::check_and_get_package_spec(arg, default_triplet, example);
+ });
for (auto&& spec : specs)
Input::check_triplet(spec.triplet(), paths);
@@ -254,15 +248,15 @@ namespace vcpkg::Commands::Install
Checks::check_exit(VCPKG_LINE_INFO, !install_plan.empty(), "Install plan cannot be empty");
// log the plan
- const std::string specs_string = Strings::join(",", install_plan, [](const InstallPlanAction& plan) {return plan.spec.to_string(); });
+ const std::string specs_string = Strings::join(",", install_plan, [](const InstallPlanAction& plan) { return plan.spec.to_string(); });
Metrics::track_property("installplan", specs_string);
print_plan(install_plan);
const bool has_non_user_requested_packages = Util::find_if(install_plan, [](const InstallPlanAction& package)-> bool
- {
- return package.request_type != RequestType::USER_REQUESTED;
- }) != install_plan.cend();
+ {
+ return package.request_type != RequestType::USER_REQUESTED;
+ }) != install_plan.cend();
if (has_non_user_requested_packages)
{