diff options
| author | Jan HrubĂ˝ <jhruby.web@gmail.com> | 2017-03-13 08:56:05 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-03-13 08:56:05 +0100 |
| commit | 665f4118f603c5858217ed7a2f2f824b18ff4fc5 (patch) | |
| tree | f0167041edf71e90f2331b5025f603392a8de67a /toolsrc/src/commands_list.cpp | |
| parent | 1bec0fcb73073b5b1719f454c368a63f1bff625e (diff) | |
| parent | 1c9873a0daf625f67474aaf3e163c592c27ecb65 (diff) | |
| download | vcpkg-665f4118f603c5858217ed7a2f2f824b18ff4fc5.tar.gz vcpkg-665f4118f603c5858217ed7a2f2f824b18ff4fc5.zip | |
Merge pull request #1 from Microsoft/master
pull
Diffstat (limited to 'toolsrc/src/commands_list.cpp')
| -rw-r--r-- | toolsrc/src/commands_list.cpp | 67 |
1 files changed, 52 insertions, 15 deletions
diff --git a/toolsrc/src/commands_list.cpp b/toolsrc/src/commands_list.cpp index 2969ea953..7bfc11f1b 100644 --- a/toolsrc/src/commands_list.cpp +++ b/toolsrc/src/commands_list.cpp @@ -1,32 +1,69 @@ +#include "pch.h" #include "vcpkg_Commands.h" -#include "vcpkg.h" +#include "vcpkglib.h" #include "vcpkg_System.h" +#include "vcpkglib_helpers.h" -namespace vcpkg +namespace vcpkg::Commands::List { - void list_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths) + static void do_print(const StatusParagraph& pgh) { - args.check_max_args(0); + System::println("%-27s %-16s %s", + pgh.package.displayname(), + pgh.package.version, + details::shorten_description(pgh.package.description)); + } + + void perform_and_exit(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths) + { + static const std::string example = Strings::format( + "The argument should be a substring to search for, or no argument to display all installed libraries.\n%s", Commands::Help::create_example_string("list png")); + args.check_max_arg_count(1, example); + args.check_and_get_optional_command_arguments({}); - std::vector<std::string> packages_output; - for (auto&& pgh : database_load_check(paths)) + const StatusParagraphs status_paragraphs = database_load_check(paths); + std::vector<StatusParagraph> installed_packages; + for (auto&& pgh : status_paragraphs) { if (pgh->state == install_state_t::not_installed && pgh->want == want_t::purge) continue; - packages_output.push_back(Strings::format("%-27s %-16s %s", - pgh->package.displayname(), - pgh->package.version, - shorten_description(pgh->package.description))); + installed_packages.push_back(*pgh); + } + + if (installed_packages.empty()) + { + System::println("No packages are installed. Did you mean `search`?"); + exit(EXIT_SUCCESS); } - std::sort(packages_output.begin(), packages_output.end()); - for (auto&& package : packages_output) + + std::sort(installed_packages.begin(), installed_packages.end(), + [ ]( const StatusParagraph& lhs, const StatusParagraph& rhs ) -> bool + { + return lhs.package.displayname() < rhs.package.displayname(); + }); + + if (args.command_arguments.size() == 0) { - System::println(package.c_str()); + for (const StatusParagraph& status_paragraph : installed_packages) + { + do_print(status_paragraph); + } } - if (packages_output.empty()) + else { - System::println("No packages are installed. Did you mean `search`?"); + // At this point there is 1 argument + for (const StatusParagraph& status_paragraph : installed_packages) + { + const std::string displayname = status_paragraph.package.displayname(); + if (Strings::case_insensitive_ascii_find(displayname, args.command_arguments[0]) == displayname.end()) + { + continue; + } + + do_print(status_paragraph); + } } + exit(EXIT_SUCCESS); } } |
