diff options
| author | Robert Schumacher <roschuma@microsoft.com> | 2017-02-08 15:12:28 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-02-08 15:12:28 -0800 |
| commit | 7ddae17e2f520e83d25f78c078bf8b8a58fff447 (patch) | |
| tree | 87e2fc5c57a685367ec051b1efbdeb5d3ab43f4d /toolsrc/src/commands_cache.cpp | |
| parent | 5e588ddb5be9e6e27cebcc3be2e1a27f3ca83a50 (diff) | |
| parent | a9f7fc6e90feaad50c1221ef9bd56e2620302215 (diff) | |
| download | vcpkg-7ddae17e2f520e83d25f78c078bf8b8a58fff447.tar.gz vcpkg-7ddae17e2f520e83d25f78c078bf8b8a58fff447.zip | |
Merge branch 'master' into master
Diffstat (limited to 'toolsrc/src/commands_cache.cpp')
| -rw-r--r-- | toolsrc/src/commands_cache.cpp | 69 |
1 files changed, 53 insertions, 16 deletions
diff --git a/toolsrc/src/commands_cache.cpp b/toolsrc/src/commands_cache.cpp index 0d70f0f29..fa49a647f 100644 --- a/toolsrc/src/commands_cache.cpp +++ b/toolsrc/src/commands_cache.cpp @@ -1,36 +1,73 @@ +#include "pch.h" #include "vcpkg_Commands.h" #include "vcpkg_System.h" #include "vcpkg_Files.h" -#include "vcpkg.h" +#include "Paragraphs.h" +#include "BinaryParagraph.h" -namespace vcpkg +namespace vcpkg::Commands::Cache { - void cache_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths) + static std::vector<BinaryParagraph> read_all_binary_paragraphs(const vcpkg_paths& paths) { - args.check_exact_arg_count(0); + std::vector<BinaryParagraph> output; + for (auto it = fs::directory_iterator(paths.packages); it != fs::directory_iterator(); ++it) + { + const fs::path& path = it->path(); + + try + { + auto file_contents = Files::read_contents(path / "CONTROL"); + if (auto text = file_contents.get()) + { + auto pghs = Paragraphs::parse_paragraphs(*text); + if (pghs.size() != 1) + continue; + + const BinaryParagraph binary_paragraph = BinaryParagraph(pghs[0]); + output.push_back(binary_paragraph); + } + } + catch (std::runtime_error const&) + { + } + } - auto begin_it = fs::directory_iterator(paths.packages); - auto end_it = fs::directory_iterator(); + return output; + } + + 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 cached libraries.\n%s", Commands::Help::create_example_string("cache png")); + args.check_max_arg_count(1, example); - if (begin_it == end_it) + const std::vector<BinaryParagraph> binary_paragraphs = read_all_binary_paragraphs(paths); + if (binary_paragraphs.empty()) { System::println("No packages are cached."); exit(EXIT_SUCCESS); } - for (; begin_it != end_it; ++begin_it) + if (args.command_arguments.size() == 0) { - const auto& path = begin_it->path(); - - auto file_contents = Files::get_contents(path / "CONTROL"); - if (auto text = file_contents.get()) + for (const BinaryParagraph& binary_paragraph : binary_paragraphs) + { + const std::string displayname = binary_paragraph.displayname(); + System::println(displayname); + } + } + else + { + // At this point there is 1 argument + for (const BinaryParagraph& binary_paragraph : binary_paragraphs) { - auto pghs = parse_paragraphs(*text); - if (pghs.size() != 1) + const std::string displayname = binary_paragraph.displayname(); + if (Strings::case_insensitive_ascii_find(displayname, args.command_arguments[0]) == displayname.end()) + { continue; + } - auto src = BinaryParagraph(pghs[0]); - System::println(src.displayname().c_str()); + System::println(displayname); } } |
