From b3e06443eab560d5de848f2a066e1baa477fa57b Mon Sep 17 00:00:00 2001 From: Maria Tavlaki Date: Sun, 1 Oct 2017 22:17:33 +0300 Subject: Create stub autocomplete function --- toolsrc/src/commands_autocomplete.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 toolsrc/src/commands_autocomplete.cpp (limited to 'toolsrc/src/commands_autocomplete.cpp') diff --git a/toolsrc/src/commands_autocomplete.cpp b/toolsrc/src/commands_autocomplete.cpp new file mode 100644 index 000000000..71154445d --- /dev/null +++ b/toolsrc/src/commands_autocomplete.cpp @@ -0,0 +1,22 @@ +#include "pch.h" + +#include "Paragraphs.h" +#include "SortedVector.h" +#include "vcpkg_Commands.h" +#include "vcpkg_Maps.h" +#include "vcpkg_System.h" + +namespace vcpkg::Commands::Autocomplete +{ + void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths) + { + static const std::string EXAMPLE = + Strings::format("The argument should be a command line to autocomplete.\n%s", + Commands::Help::create_example_string("autocomplete install z")); + + args.check_max_arg_count(1, EXAMPLE); + args.check_and_get_optional_command_arguments({}); + + Checks::exit_success(VCPKG_LINE_INFO); + } +} -- cgit v1.2.3 From fe89e72e9565f0515834b925f015fe19324c38da Mon Sep 17 00:00:00 2001 From: Maria Tavlaki Date: Sun, 1 Oct 2017 23:26:36 +0300 Subject: Autocomplete: handle arguments --- toolsrc/src/commands_autocomplete.cpp | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'toolsrc/src/commands_autocomplete.cpp') diff --git a/toolsrc/src/commands_autocomplete.cpp b/toolsrc/src/commands_autocomplete.cpp index 71154445d..a67113aff 100644 --- a/toolsrc/src/commands_autocomplete.cpp +++ b/toolsrc/src/commands_autocomplete.cpp @@ -14,9 +14,34 @@ namespace vcpkg::Commands::Autocomplete Strings::format("The argument should be a command line to autocomplete.\n%s", Commands::Help::create_example_string("autocomplete install z")); - args.check_max_arg_count(1, EXAMPLE); + args.check_min_arg_count(1, EXAMPLE); + args.check_max_arg_count(2, EXAMPLE); args.check_and_get_optional_command_arguments({}); + const std::string requested_command = args.command_arguments.at(0); + const std::string start_with = + args.command_arguments.size() > 1 ? args.command_arguments.at(1) : Strings::EMPTY; + + auto sources_and_errors = Paragraphs::try_load_all_ports(paths.get_filesystem(), paths.ports); + auto& source_paragraphs = sources_and_errors.paragraphs; + + const auto& istartswith = Strings::case_insensitive_ascii_starts_with; + + std::vector results; + for (const auto& source_control_file : source_paragraphs) + { + auto&& sp = *source_control_file->core_paragraph; + + if (istartswith(sp.name, start_with)) + { + results.push_back(sp.name); + } + } + + System::println(Strings::join(" ", results)); + + auto all_ports = Paragraphs::try_load_all_ports(paths.get_filesystem(), paths.ports); + Checks::exit_success(VCPKG_LINE_INFO); } } -- cgit v1.2.3 From 7c2239f980197096a13e8fb4b96297b08616eb78 Mon Sep 17 00:00:00 2001 From: Maria Tavlaki Date: Mon, 2 Oct 2017 00:03:39 +0300 Subject: Autocomplete: check if first argument is "install" --- toolsrc/src/commands_autocomplete.cpp | 37 ++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 16 deletions(-) (limited to 'toolsrc/src/commands_autocomplete.cpp') diff --git a/toolsrc/src/commands_autocomplete.cpp b/toolsrc/src/commands_autocomplete.cpp index a67113aff..013cea320 100644 --- a/toolsrc/src/commands_autocomplete.cpp +++ b/toolsrc/src/commands_autocomplete.cpp @@ -8,6 +8,23 @@ namespace vcpkg::Commands::Autocomplete { + std::vector autocomplete_install( + const std::vector>& source_paragraphs, const std::string& start_with) + { + std::vector results; + const auto& istartswith = Strings::case_insensitive_ascii_starts_with; + + for (const auto& source_control_file : source_paragraphs) + { + auto&& sp = *source_control_file->core_paragraph; + + if (istartswith(sp.name, start_with)) + { + results.push_back(sp.name); + } + } + return results; + } void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths) { static const std::string EXAMPLE = @@ -21,27 +38,15 @@ namespace vcpkg::Commands::Autocomplete const std::string requested_command = args.command_arguments.at(0); const std::string start_with = args.command_arguments.size() > 1 ? args.command_arguments.at(1) : Strings::EMPTY; - - auto sources_and_errors = Paragraphs::try_load_all_ports(paths.get_filesystem(), paths.ports); - auto& source_paragraphs = sources_and_errors.paragraphs; - - const auto& istartswith = Strings::case_insensitive_ascii_starts_with; - std::vector results; - for (const auto& source_control_file : source_paragraphs) + if (requested_command == "install") { - auto&& sp = *source_control_file->core_paragraph; + auto sources_and_errors = Paragraphs::try_load_all_ports(paths.get_filesystem(), paths.ports); + auto& source_paragraphs = sources_and_errors.paragraphs; - if (istartswith(sp.name, start_with)) - { - results.push_back(sp.name); - } + results = autocomplete_install(source_paragraphs, start_with); } - System::println(Strings::join(" ", results)); - - auto all_ports = Paragraphs::try_load_all_ports(paths.get_filesystem(), paths.ports); - Checks::exit_success(VCPKG_LINE_INFO); } } -- cgit v1.2.3 From 016c53e231f353bdfa35f8e265b281e8d56031ed Mon Sep 17 00:00:00 2001 From: Maria Tavlaki Date: Mon, 2 Oct 2017 00:38:53 +0300 Subject: Autocomplete: remove --- toolsrc/src/commands_autocomplete.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'toolsrc/src/commands_autocomplete.cpp') diff --git a/toolsrc/src/commands_autocomplete.cpp b/toolsrc/src/commands_autocomplete.cpp index 013cea320..3963f904b 100644 --- a/toolsrc/src/commands_autocomplete.cpp +++ b/toolsrc/src/commands_autocomplete.cpp @@ -5,6 +5,7 @@ #include "vcpkg_Commands.h" #include "vcpkg_Maps.h" #include "vcpkg_System.h" +#include "vcpkglib.h" namespace vcpkg::Commands::Autocomplete { @@ -25,6 +26,25 @@ namespace vcpkg::Commands::Autocomplete } return results; } + + std::vector autocomplete_remove(std::vector installed_packages, + const std::string& start_with) + { + std::vector results; + const auto& istartswith = Strings::case_insensitive_ascii_starts_with; + + for (const auto& installed_package : installed_packages) + { + auto sp = installed_package->package.displayname(); + + if (istartswith(sp, start_with)) + { + results.push_back(sp); + } + } + return results; + } + void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths) { static const std::string EXAMPLE = @@ -46,6 +66,13 @@ namespace vcpkg::Commands::Autocomplete results = autocomplete_install(source_paragraphs, start_with); } + else if (requested_command == "remove") + { + const StatusParagraphs status_db = database_load_check(paths); + std::vector installed_packages = get_installed_ports(status_db); + results = autocomplete_remove(installed_packages, start_with); + } + System::println(Strings::join(" ", results)); Checks::exit_success(VCPKG_LINE_INFO); } -- cgit v1.2.3