aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/src/commands_cache.cpp
diff options
context:
space:
mode:
authorJan HrubĂ˝ <jhruby.web@gmail.com>2017-03-13 08:56:05 +0100
committerGitHub <noreply@github.com>2017-03-13 08:56:05 +0100
commit665f4118f603c5858217ed7a2f2f824b18ff4fc5 (patch)
treef0167041edf71e90f2331b5025f603392a8de67a /toolsrc/src/commands_cache.cpp
parent1bec0fcb73073b5b1719f454c368a63f1bff625e (diff)
parent1c9873a0daf625f67474aaf3e163c592c27ecb65 (diff)
downloadvcpkg-665f4118f603c5858217ed7a2f2f824b18ff4fc5.tar.gz
vcpkg-665f4118f603c5858217ed7a2f2f824b18ff4fc5.zip
Merge pull request #1 from Microsoft/master
pull
Diffstat (limited to 'toolsrc/src/commands_cache.cpp')
-rw-r--r--toolsrc/src/commands_cache.cpp70
1 files changed, 54 insertions, 16 deletions
diff --git a/toolsrc/src/commands_cache.cpp b/toolsrc/src/commands_cache.cpp
index 3a08c4a64..e255b5dff 100644
--- a/toolsrc/src/commands_cache.cpp
+++ b/toolsrc/src/commands_cache.cpp
@@ -1,36 +1,74 @@
+#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_max_args(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);
+ args.check_and_get_optional_command_arguments({});
- 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);
}
}