aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/src/commands_autocomplete.cpp
diff options
context:
space:
mode:
authorAlexander Karatarakis <alkarata@microsoft.com>2017-10-12 14:03:01 -0700
committerAlexander Karatarakis <alkarata@microsoft.com>2017-10-12 14:03:37 -0700
commit9e19c24d2911ff1ef648aeed0c596e3987eafebf (patch)
treecd09d98631a6d99df7fbb7a48cf8488ad02c9c48 /toolsrc/src/commands_autocomplete.cpp
parent53ad1402514481c581a7b3bd1b0ffbcea9aaa902 (diff)
downloadvcpkg-9e19c24d2911ff1ef648aeed0c596e3987eafebf.tar.gz
vcpkg-9e19c24d2911ff1ef648aeed0c596e3987eafebf.zip
`vcpkg autocomplete` More work on autocomplete
Diffstat (limited to 'toolsrc/src/commands_autocomplete.cpp')
-rw-r--r--toolsrc/src/commands_autocomplete.cpp83
1 files changed, 61 insertions, 22 deletions
diff --git a/toolsrc/src/commands_autocomplete.cpp b/toolsrc/src/commands_autocomplete.cpp
index 3963f904b..abad19df7 100644
--- a/toolsrc/src/commands_autocomplete.cpp
+++ b/toolsrc/src/commands_autocomplete.cpp
@@ -1,9 +1,8 @@
#include "pch.h"
#include "Paragraphs.h"
-#include "SortedVector.h"
+#include "metrics.h"
#include "vcpkg_Commands.h"
-#include "vcpkg_Maps.h"
#include "vcpkg_System.h"
#include "vcpkglib.h"
@@ -35,7 +34,7 @@ namespace vcpkg::Commands::Autocomplete
for (const auto& installed_package : installed_packages)
{
- auto sp = installed_package->package.displayname();
+ const auto sp = installed_package->package.displayname();
if (istartswith(sp, start_with))
{
@@ -47,33 +46,73 @@ 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"));
+ Metrics::g_metrics.lock()->set_send_metrics(false);
- args.check_min_arg_count(1, EXAMPLE);
- args.check_max_arg_count(2, EXAMPLE);
- args.check_and_get_optional_command_arguments({});
+ if (args.command_arguments.size() != 1)
+ {
+ Checks::exit_success(VCPKG_LINE_INFO);
+ }
- 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;
- std::vector<std::string> results;
- if (requested_command == "install")
+ const std::string to_autocomplete = args.command_arguments.at(0);
+ const std::vector<std::string> tokens = Strings::split(to_autocomplete, " ");
+ if (tokens.size() == 1)
{
- auto sources_and_errors = Paragraphs::try_load_all_ports(paths.get_filesystem(), paths.ports);
- auto& source_paragraphs = sources_and_errors.paragraphs;
+ const std::string requested_command = tokens[0];
+
+ std::vector<std::string> valid_commands = {"install",
+ "search",
+ "remove",
+ "list",
+ "update",
+ "hash",
+ "help",
+ "integrate",
+ "export",
+ "edit",
+ "create",
+ "owns",
+ "cache",
+ "version",
+ "contact"};
+
+ Util::unstable_keep_if(valid_commands, [&](const std::string& s) {
+ return Strings::case_insensitive_ascii_starts_with(s, requested_command);
+ });
- results = autocomplete_install(source_paragraphs, start_with);
+ if (valid_commands.size() == 1)
+ {
+ System::println(valid_commands[0] + " ");
+ }
+ else
+ {
+ System::println(Strings::join("\n", valid_commands));
+ }
+
+ Checks::exit_success(VCPKG_LINE_INFO);
}
- else if (requested_command == "remove")
+
+ if (tokens.size() == 2)
{
- const StatusParagraphs status_db = database_load_check(paths);
- std::vector<StatusParagraph*> installed_packages = get_installed_ports(status_db);
- results = autocomplete_remove(installed_packages, start_with);
+ const std::string requested_command = tokens[0];
+ const std::string start_with = tokens[1];
+ std::vector<std::string> results;
+ if (requested_command == "install")
+ {
+ auto sources_and_errors = Paragraphs::try_load_all_ports(paths.get_filesystem(), paths.ports);
+ auto& source_paragraphs = sources_and_errors.paragraphs;
+
+ results = autocomplete_install(source_paragraphs, start_with);
+ }
+ else if (requested_command == "remove")
+ {
+ const StatusParagraphs status_db = database_load_check(paths);
+ const std::vector<StatusParagraph*> installed_packages = get_installed_ports(status_db);
+ results = autocomplete_remove(installed_packages, start_with);
+ }
+
+ System::println(Strings::join("\n", results));
}
- System::println(Strings::join(" ", results));
Checks::exit_success(VCPKG_LINE_INFO);
}
}