message: `vcpkg autocomplete` More work on autocomplete
diff: #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,17 +46,55 @@ 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 to_autocomplete = args.command_arguments.at(0);
  + const std::vector<std::string> tokens = Strings::split(to_autocomplete, " ");
  + if (tokens.size() == 1)
  + {
  + 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);
  + });
  +
  + if (valid_commands.size() == 1)
  + {
  + System::println(valid_commands[0] + " ");
  + }
  + else
  + {
  + System::println(Strings::join("\n", valid_commands));
  + }
  - 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;
  + Checks::exit_success(VCPKG_LINE_INFO);
  + }
  +
  + if (tokens.size() == 2)
  + {
  + const std::string requested_command = tokens[0];
  + const std::string start_with = tokens[1];
  std::vector<std::string> results;
  if (requested_command == "install")
  {
  @@ -69,11 +106,13 @@ namespace vcpkg::Commands::Autocomplete
  else if (requested_command == "remove")
  {
  const StatusParagraphs status_db = database_load_check(paths);
  - std::vector<StatusParagraph*> installed_packages = get_installed_ports(status_db);
  + const std::vector<StatusParagraph*> installed_packages = get_installed_ports(status_db);
  results = autocomplete_remove(installed_packages, start_with);
  }
  - System::println(Strings::join(" ", results));
  + System::println(Strings::join("\n", results));
  + }
  +
  Checks::exit_success(VCPKG_LINE_INFO);
  }
  }
  