From 8f162188ddef5841f50250ef92bf629eac512650 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 7 Nov 2016 13:44:20 -0800 Subject: Add simple substring filtering to `vcpkg cache`, like `vcpkg search` --- toolsrc/src/commands_cache.cpp | 61 +++++++++++++++++++++++++++++++----------- 1 file changed, 46 insertions(+), 15 deletions(-) (limited to 'toolsrc/src/commands_cache.cpp') diff --git a/toolsrc/src/commands_cache.cpp b/toolsrc/src/commands_cache.cpp index 0d70f0f29..53518264e 100644 --- a/toolsrc/src/commands_cache.cpp +++ b/toolsrc/src/commands_cache.cpp @@ -5,34 +5,65 @@ namespace vcpkg { - void cache_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths) + template + static void do_print(const vcpkg_paths& paths, Pred predicate) { - args.check_exact_arg_count(0); - - auto begin_it = fs::directory_iterator(paths.packages); - auto end_it = fs::directory_iterator(); + auto it = fs::directory_iterator(paths.packages); + const fs::directory_iterator end_it = fs::directory_iterator(); - if (begin_it == end_it) + if (it == end_it) { System::println("No packages are cached."); exit(EXIT_SUCCESS); } - for (; begin_it != end_it; ++begin_it) + for (; it != end_it; ++it) { - const auto& path = begin_it->path(); + const fs::path& path = it->path(); - auto file_contents = Files::get_contents(path / "CONTROL"); - if (auto text = file_contents.get()) + try { - auto pghs = parse_paragraphs(*text); - if (pghs.size() != 1) - continue; + auto file_contents = Files::get_contents(path / "CONTROL"); + if (auto text = file_contents.get()) + { + auto pghs = parse_paragraphs(*text); + if (pghs.size() != 1) + continue; - auto src = BinaryParagraph(pghs[0]); - System::println(src.displayname().c_str()); + const BinaryParagraph src = BinaryParagraph(pghs[0]); + const std::string displayname = src.displayname(); + if (predicate(displayname)) + { + System::println(displayname.c_str()); + } + } + } + catch (std::runtime_error const&) + { } } + } + + void cache_command(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", create_example_string("cache png")); + args.check_max_arg_count(1, example.c_str()); + + if (args.command_arguments.size() == 0) + { + do_print(paths, [](const std::string&) -> bool + { + return true; + }); + exit(EXIT_SUCCESS); + } + + // At this point there is 1 argument + do_print(paths, [&](const std::string& port_name) -> bool + { + return Strings::case_insensitive_ascii_find(port_name, args.command_arguments[0]) != port_name.end(); + }); exit(EXIT_SUCCESS); } -- cgit v1.2.3 From 7e05c53628e686e5e2aa39e185789c2b6146f35b Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 7 Nov 2016 14:06:51 -0800 Subject: Rework `vcpkg cache` implementation --- toolsrc/src/commands_cache.cpp | 60 ++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 28 deletions(-) (limited to 'toolsrc/src/commands_cache.cpp') diff --git a/toolsrc/src/commands_cache.cpp b/toolsrc/src/commands_cache.cpp index 53518264e..5e20a39af 100644 --- a/toolsrc/src/commands_cache.cpp +++ b/toolsrc/src/commands_cache.cpp @@ -5,19 +5,10 @@ namespace vcpkg { - template - static void do_print(const vcpkg_paths& paths, Pred predicate) + static std::vector read_all_binary_paragraphs(const vcpkg_paths& paths) { - auto it = fs::directory_iterator(paths.packages); - const fs::directory_iterator end_it = fs::directory_iterator(); - - if (it == end_it) - { - System::println("No packages are cached."); - exit(EXIT_SUCCESS); - } - - for (; it != end_it; ++it) + std::vector output; + for (auto it = fs::directory_iterator(paths.packages); it != fs::directory_iterator(); ++it) { const fs::path& path = it->path(); @@ -30,18 +21,16 @@ namespace vcpkg if (pghs.size() != 1) continue; - const BinaryParagraph src = BinaryParagraph(pghs[0]); - const std::string displayname = src.displayname(); - if (predicate(displayname)) - { - System::println(displayname.c_str()); - } + const BinaryParagraph binary_paragraph = BinaryParagraph(pghs[0]); + output.push_back(binary_paragraph); } } catch (std::runtime_error const&) { } } + + return output; } void cache_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths) @@ -50,20 +39,35 @@ namespace vcpkg "The argument should be a substring to search for, or no argument to display all cached libraries.\n%s", create_example_string("cache png")); args.check_max_arg_count(1, example.c_str()); - if (args.command_arguments.size() == 0) + const std::vector binary_paragraphs = read_all_binary_paragraphs(paths); + if (binary_paragraphs.empty()) { - do_print(paths, [](const std::string&) -> bool - { - return true; - }); + System::println("No packages are cached."); exit(EXIT_SUCCESS); } - // At this point there is 1 argument - do_print(paths, [&](const std::string& port_name) -> bool - { - return Strings::case_insensitive_ascii_find(port_name, args.command_arguments[0]) != port_name.end(); - }); + if (args.command_arguments.size() == 0) + { + for (const BinaryParagraph& binary_paragraph : binary_paragraphs) + { + const std::string displayname = binary_paragraph.displayname(); + System::println(displayname.c_str()); + } + } + else + { + // At this point there is 1 argument + for (const BinaryParagraph& binary_paragraph : binary_paragraphs) + { + const std::string displayname = binary_paragraph.displayname(); + if (Strings::case_insensitive_ascii_find(displayname, args.command_arguments[0]) == displayname.end()) + { + continue; + } + + System::println(displayname.c_str()); + } + } exit(EXIT_SUCCESS); } -- cgit v1.2.3 From a721db2c1fbfc1b87065b0b43e32249117e53242 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 7 Nov 2016 16:06:36 -0800 Subject: Refactor: create new Paragraphs.h/cpp --- toolsrc/src/commands_cache.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'toolsrc/src/commands_cache.cpp') diff --git a/toolsrc/src/commands_cache.cpp b/toolsrc/src/commands_cache.cpp index 5e20a39af..634a72a64 100644 --- a/toolsrc/src/commands_cache.cpp +++ b/toolsrc/src/commands_cache.cpp @@ -2,6 +2,7 @@ #include "vcpkg_System.h" #include "vcpkg_Files.h" #include "vcpkg.h" +#include "Paragraphs.h" namespace vcpkg { @@ -17,7 +18,7 @@ namespace vcpkg auto file_contents = Files::get_contents(path / "CONTROL"); if (auto text = file_contents.get()) { - auto pghs = parse_paragraphs(*text); + auto pghs = Paragraphs::parse_paragraphs(*text); if (pghs.size() != 1) continue; -- cgit v1.2.3 From 8adaaea6fc7f2aa99f1ec8d894ad7036805bf76a Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 7 Nov 2016 17:32:27 -0800 Subject: [cache] Don't #include "vcpkg.h" --- toolsrc/src/commands_cache.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'toolsrc/src/commands_cache.cpp') diff --git a/toolsrc/src/commands_cache.cpp b/toolsrc/src/commands_cache.cpp index 634a72a64..19c762caf 100644 --- a/toolsrc/src/commands_cache.cpp +++ b/toolsrc/src/commands_cache.cpp @@ -1,8 +1,8 @@ #include "vcpkg_Commands.h" #include "vcpkg_System.h" #include "vcpkg_Files.h" -#include "vcpkg.h" #include "Paragraphs.h" +#include "BinaryParagraph.h" namespace vcpkg { -- cgit v1.2.3 From b629cd904440c640b7e5b4c3fdf17df5aac90bad Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 12 Dec 2016 15:03:36 -0800 Subject: [vcpkg_cmd_arguments] Use std::string instead of char* --- toolsrc/src/commands_cache.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'toolsrc/src/commands_cache.cpp') diff --git a/toolsrc/src/commands_cache.cpp b/toolsrc/src/commands_cache.cpp index 19c762caf..f43b054a6 100644 --- a/toolsrc/src/commands_cache.cpp +++ b/toolsrc/src/commands_cache.cpp @@ -38,7 +38,7 @@ namespace vcpkg { 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", create_example_string("cache png")); - args.check_max_arg_count(1, example.c_str()); + args.check_max_arg_count(1, example); const std::vector binary_paragraphs = read_all_binary_paragraphs(paths); if (binary_paragraphs.empty()) -- cgit v1.2.3 From 9796e2532cc34896e38a6c0702e538454ffb5586 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 12 Dec 2016 15:10:29 -0800 Subject: Use System::println(std::string&) overload --- toolsrc/src/commands_cache.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'toolsrc/src/commands_cache.cpp') diff --git a/toolsrc/src/commands_cache.cpp b/toolsrc/src/commands_cache.cpp index f43b054a6..17b04b093 100644 --- a/toolsrc/src/commands_cache.cpp +++ b/toolsrc/src/commands_cache.cpp @@ -52,7 +52,7 @@ namespace vcpkg for (const BinaryParagraph& binary_paragraph : binary_paragraphs) { const std::string displayname = binary_paragraph.displayname(); - System::println(displayname.c_str()); + System::println(displayname); } } else @@ -66,7 +66,7 @@ namespace vcpkg continue; } - System::println(displayname.c_str()); + System::println(displayname); } } -- cgit v1.2.3 From aad0cc4c042aad87b2b52eded0e465ed01e799c1 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Fri, 16 Dec 2016 19:40:58 -0800 Subject: Files::get_contents() -> Files::read_contents() --- toolsrc/src/commands_cache.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'toolsrc/src/commands_cache.cpp') diff --git a/toolsrc/src/commands_cache.cpp b/toolsrc/src/commands_cache.cpp index 17b04b093..1a10b93cf 100644 --- a/toolsrc/src/commands_cache.cpp +++ b/toolsrc/src/commands_cache.cpp @@ -15,7 +15,7 @@ namespace vcpkg try { - auto file_contents = Files::get_contents(path / "CONTROL"); + auto file_contents = Files::read_contents(path / "CONTROL"); if (auto text = file_contents.get()) { auto pghs = Paragraphs::parse_paragraphs(*text); -- cgit v1.2.3 From df2a05e8546281135c6ea12430734d74371bcf46 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Thu, 12 Jan 2017 17:35:33 -0800 Subject: Introduce Command namespace. Refactoring --- toolsrc/src/commands_cache.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'toolsrc/src/commands_cache.cpp') diff --git a/toolsrc/src/commands_cache.cpp b/toolsrc/src/commands_cache.cpp index 1a10b93cf..3d2916418 100644 --- a/toolsrc/src/commands_cache.cpp +++ b/toolsrc/src/commands_cache.cpp @@ -4,7 +4,7 @@ #include "Paragraphs.h" #include "BinaryParagraph.h" -namespace vcpkg +namespace vcpkg::Commands { static std::vector read_all_binary_paragraphs(const vcpkg_paths& paths) { @@ -37,7 +37,7 @@ namespace vcpkg void cache_command(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", create_example_string("cache png")); + "The argument should be a substring to search for, or no argument to display all cached libraries.\n%s", Commands::Helpers::create_example_string("cache png")); args.check_max_arg_count(1, example); const std::vector binary_paragraphs = read_all_binary_paragraphs(paths); -- cgit v1.2.3 From cc8851144a871931b93d84bd962364159ad1c424 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Thu, 12 Jan 2017 22:03:57 -0800 Subject: Reorganize commands, each in its own namespace Additionally, functions related to a command can now live in the same namespace --- toolsrc/src/commands_cache.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'toolsrc/src/commands_cache.cpp') diff --git a/toolsrc/src/commands_cache.cpp b/toolsrc/src/commands_cache.cpp index 3d2916418..63bf32260 100644 --- a/toolsrc/src/commands_cache.cpp +++ b/toolsrc/src/commands_cache.cpp @@ -4,7 +4,7 @@ #include "Paragraphs.h" #include "BinaryParagraph.h" -namespace vcpkg::Commands +namespace vcpkg::Commands::Cache { static std::vector read_all_binary_paragraphs(const vcpkg_paths& paths) { @@ -34,10 +34,10 @@ namespace vcpkg::Commands return output; } - void cache_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths) + 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::Helpers::create_example_string("cache png")); + "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); const std::vector binary_paragraphs = read_all_binary_paragraphs(paths); -- cgit v1.2.3 From 050e4a0f7a8156bd862f95c06ea298ab6697e147 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Fri, 27 Jan 2017 12:49:09 -0800 Subject: Introduce precompiled headers --- toolsrc/src/commands_cache.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'toolsrc/src/commands_cache.cpp') diff --git a/toolsrc/src/commands_cache.cpp b/toolsrc/src/commands_cache.cpp index 63bf32260..fa49a647f 100644 --- a/toolsrc/src/commands_cache.cpp +++ b/toolsrc/src/commands_cache.cpp @@ -1,3 +1,4 @@ +#include "pch.h" #include "vcpkg_Commands.h" #include "vcpkg_System.h" #include "vcpkg_Files.h" -- cgit v1.2.3