Add "add" command and fix bug where forwarded arguments include the selection command.
ADD
include/vcpkg/commands.add.h
+#pragma once
+
+#include <vcpkg/commands.interface.h>
+
+namespace vcpkg::Commands
+{
+ struct AddCommand : PathsCommand
+ {
+ void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths) const override;
+ };
+}

MODIFY
include/vcpkg/configure-environment.h
include/vcpkg/configure-environment.h
namespace vcpkg
{
- int run_configure_environment_command(const VcpkgPaths& paths, View<std::string> args = {});
- int run_configure_environment_command(const VcpkgPaths& paths, StringView arg0, View<std::string> args = {});
+ int run_configure_environment_command(const VcpkgPaths& paths, View<std::string> args);
+ int run_configure_environment_command(const VcpkgPaths& paths, StringView arg0, View<std::string> args);
}

ADD
src/vcpkg/commands.add.cpp
+#include <vcpkg/base/basic_checks.h>
+#include <vcpkg/base/strings.h>
+
+#include <vcpkg/commands.add.h>
+#include <vcpkg/configure-environment.h>
+#include <vcpkg/vcpkgcmdarguments.h>
+#include <vcpkg/vcpkgpaths.h>
+
+using namespace vcpkg;
+
+namespace
+{
+ const CommandStructure AddCommandStructure = {
+ Strings::format(
+ "Adds the indicated port or artifact to the manifest associated with the current directory.\n%s\n%s",
+ create_example_string("add port png"),
+ create_example_string("add artifact cmake")),
+ 2,
+ 2,
+ {{}, {}},
+ nullptr,
+ };
+}
+
+namespace vcpkg::Commands
+{
+ void AddCommand::perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths) const
+ {
+ args.parse_arguments(AddCommandStructure);
+ auto&& selector = args.command_arguments[0];
+ if (selector == "artifact")
+ {
+ std::string ce_args[] = {"add", args.command_arguments[1]};
+ Checks::exit_with_code(VCPKG_LINE_INFO, run_configure_environment_command(paths, ce_args));
+ }
+
+ if (selector == "port")
+ {
+ auto manifest = paths.get_manifest().get();
+ if (!manifest)
+ {
+ Checks::exit_with_message(VCPKG_LINE_INFO, "add port requires an active manifest file.\n");
+ }
+
+ Checks::exit_with_message(VCPKG_LINE_INFO, "add port will be added in a future vcpkg release.\n");
+ }
+
+ Checks::exit_with_message(VCPKG_LINE_INFO, "The first parmaeter to add must be 'artifact' or 'port'.\n");
+ }
+}

MODIFY
src/vcpkg/commands.cpp
src/vcpkg/commands.cpp
#include <vcpkg/build.h>
#include <vcpkg/commands.activate.h>
#include <vcpkg/commands.add-version.h>
+#include <vcpkg/commands.add.h>
#include <vcpkg/commands.autocomplete.h>
#include <vcpkg/commands.buildexternal.h>
#include <vcpkg/commands.cache.h>
@@ -77,6 +78,7 @@ namespace vcpkg::Commands
Span<const PackageNameAndFunction<const PathsCommand*>> get_available_paths_commands()
{
static const Activate::ActivateCommand activate{};
+ static const AddCommand add{};
static const AddVersion::AddVersionCommand add_version{};
static const Autocomplete::AutocompleteCommand autocomplete{};
static const Cache::CacheCommand cache{};
@@ -103,6 +105,7 @@ namespace vcpkg::Commands
{"/?", &help},
{"help", &help},
{"activate", &activate},
+ {"add", &add},
{"autocomplete", &autocomplete},
{"cache", &cache},
{"create", &create},

MODIFY
src/vcpkg/vcpkgcmdarguments.cpp
src/vcpkg/vcpkgcmdarguments.cpp
@@ -236,7 +236,14 @@ namespace vcpkg
VcpkgCmdArguments args;
std::vector<std::string> feature_flags;
- args.forwardable_arguments.assign(arg_first, arg_last);
+ if (arg_first == arg_last)
+ {
+ args.forwardable_arguments.clear();
+ }
+ else
+ {
+ args.forwardable_arguments.assign(arg_first + 1, arg_last);
+ }
if (arg_first != arg_last && arg_first + 1 == arg_last && *arg_first == "--version")
{

Add "add" command and fix bug where forwarded arguments include the selection command.