aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornicole mazzuca <mazzucan@outlook.com>2020-07-15 17:29:18 -0700
committerGitHub <noreply@github.com>2020-07-15 17:29:18 -0700
commit6bf5adff937abd9bf09fb1c3fda40b5f566f8acd (patch)
treedad4795f852b4af3252e8f51f90ba4e5b0b3d835
parent5a4e2c0484878a28f27ffd66caf39cc3507ca205 (diff)
downloadvcpkg-6bf5adff937abd9bf09fb1c3fda40b5f566f8acd.tar.gz
vcpkg-6bf5adff937abd9bf09fb1c3fda40b5f566f8acd.zip
[vcpkg] Clean up command switch code (#12351)
* [vcpkg] Clean up command switch code Make it more similar to the non-command switch code * format * fix the tests * reformat * format * wip * support x- for command options * fix autocomplete * format
-rw-r--r--toolsrc/include/vcpkg/vcpkgcmdarguments.h3
-rw-r--r--toolsrc/src/vcpkg-test/arguments.cpp16
-rw-r--r--toolsrc/src/vcpkg/commands.autocomplete.cpp12
-rw-r--r--toolsrc/src/vcpkg/commands.ci.cpp10
-rw-r--r--toolsrc/src/vcpkg/commands.contact.cpp2
-rw-r--r--toolsrc/src/vcpkg/commands.dependinfo.cpp10
-rw-r--r--toolsrc/src/vcpkg/commands.edit.cpp4
-rw-r--r--toolsrc/src/vcpkg/commands.env.cpp10
-rw-r--r--toolsrc/src/vcpkg/commands.format-manifest.cpp2
-rw-r--r--toolsrc/src/vcpkg/commands.list.cpp3
-rw-r--r--toolsrc/src/vcpkg/commands.search.cpp3
-rw-r--r--toolsrc/src/vcpkg/commands.setinstalled.cpp4
-rw-r--r--toolsrc/src/vcpkg/commands.upgrade.cpp4
-rw-r--r--toolsrc/src/vcpkg/export.chocolatey.cpp2
-rw-r--r--toolsrc/src/vcpkg/export.cpp54
-rw-r--r--toolsrc/src/vcpkg/install.cpp22
-rw-r--r--toolsrc/src/vcpkg/remove.cpp10
-rw-r--r--toolsrc/src/vcpkg/vcpkgcmdarguments.cpp212
18 files changed, 195 insertions, 188 deletions
diff --git a/toolsrc/include/vcpkg/vcpkgcmdarguments.h b/toolsrc/include/vcpkg/vcpkgcmdarguments.h
index 8cf0680b9..ddc407a35 100644
--- a/toolsrc/include/vcpkg/vcpkgcmdarguments.h
+++ b/toolsrc/include/vcpkg/vcpkgcmdarguments.h
@@ -182,6 +182,7 @@ namespace vcpkg
void track_feature_flag_metrics() const;
private:
- std::unordered_map<std::string, Optional<std::vector<std::string>>> optional_command_arguments;
+ std::unordered_set<std::string> command_switches;
+ std::unordered_map<std::string, std::vector<std::string>> command_options;
};
}
diff --git a/toolsrc/src/vcpkg-test/arguments.cpp b/toolsrc/src/vcpkg-test/arguments.cpp
index 3ce4c5a9b..7ade6aa2a 100644
--- a/toolsrc/src/vcpkg-test/arguments.cpp
+++ b/toolsrc/src/vcpkg-test/arguments.cpp
@@ -77,14 +77,14 @@ TEST_CASE ("VcpkgCmdArguments from argument sequence with valued options", "[arg
{
SECTION ("case 1")
{
- std::array<CommandSetting, 1> settings = {{{"--a", ""}}};
+ std::array<CommandSetting, 1> settings = {{{"a", ""}}};
CommandStructure cmdstruct = {"", 0, SIZE_MAX, {{}, settings}, nullptr};
std::vector<std::string> t = {"--a=b", "command", "argument"};
auto v = VcpkgCmdArguments::create_from_arg_sequence(t.data(), t.data() + t.size());
auto opts = v.parse_arguments(cmdstruct);
- REQUIRE(opts.settings["--a"] == "b");
+ REQUIRE(opts.settings["a"] == "b");
REQUIRE(v.command_arguments.size() == 1);
REQUIRE(v.command_arguments[0] == "argument");
REQUIRE(v.command == "command");
@@ -92,18 +92,18 @@ TEST_CASE ("VcpkgCmdArguments from argument sequence with valued options", "[arg
SECTION ("case 2")
{
- std::array<CommandSwitch, 2> switches = {{{"--a", ""}, {"--c", ""}}};
- std::array<CommandSetting, 2> settings = {{{"--b", ""}, {"--d", ""}}};
+ std::array<CommandSwitch, 2> switches = {{{"a", ""}, {"c", ""}}};
+ std::array<CommandSetting, 2> settings = {{{"b", ""}, {"d", ""}}};
CommandStructure cmdstruct = {"", 0, SIZE_MAX, {switches, settings}, nullptr};
std::vector<std::string> t = {"--a", "--b=c"};
auto v = VcpkgCmdArguments::create_from_arg_sequence(t.data(), t.data() + t.size());
auto opts = v.parse_arguments(cmdstruct);
- REQUIRE(opts.settings["--b"] == "c");
- REQUIRE(opts.settings.find("--d") == opts.settings.end());
- REQUIRE(opts.switches.find("--a") != opts.switches.end());
- REQUIRE(opts.settings.find("--c") == opts.settings.end());
+ REQUIRE(opts.settings["b"] == "c");
+ REQUIRE(opts.settings.find("d") == opts.settings.end());
+ REQUIRE(opts.switches.find("a") != opts.switches.end());
+ REQUIRE(opts.settings.find("c") == opts.settings.end());
REQUIRE(v.command_arguments.size() == 0);
}
}
diff --git a/toolsrc/src/vcpkg/commands.autocomplete.cpp b/toolsrc/src/vcpkg/commands.autocomplete.cpp
index 611c78cbe..17d38f395 100644
--- a/toolsrc/src/vcpkg/commands.autocomplete.cpp
+++ b/toolsrc/src/vcpkg/commands.autocomplete.cpp
@@ -138,11 +138,17 @@ namespace vcpkg::Commands::Autocomplete
const bool is_option = Strings::case_insensitive_ascii_starts_with(prefix, "-");
if (is_option)
{
- results = Util::fmap(command.structure.options.switches,
- [](const CommandSwitch& s) -> std::string { return s.name.to_string(); });
+ results = Util::fmap(command.structure.options.switches, [](const CommandSwitch& s) -> std::string {
+ return Strings::format("--%s", s.name.to_string());
+ });
- auto settings = Util::fmap(command.structure.options.settings, [](auto&& s) { return s.name; });
+ auto settings = Util::fmap(command.structure.options.settings,
+ [](auto&& s) { return Strings::format("--%s", s.name); });
results.insert(results.end(), settings.begin(), settings.end());
+
+ auto multisettings = Util::fmap(command.structure.options.multisettings,
+ [](auto&& s) { return Strings::format("--%s", s.name); });
+ results.insert(results.end(), multisettings.begin(), multisettings.end());
}
else
{
diff --git a/toolsrc/src/vcpkg/commands.ci.cpp b/toolsrc/src/vcpkg/commands.ci.cpp
index ef0e07794..50336a4c1 100644
--- a/toolsrc/src/vcpkg/commands.ci.cpp
+++ b/toolsrc/src/vcpkg/commands.ci.cpp
@@ -82,11 +82,11 @@ namespace vcpkg::Commands::CI
Install::InstallSummary summary;
};
- static constexpr StringLiteral OPTION_DRY_RUN = "--dry-run";
- static constexpr StringLiteral OPTION_EXCLUDE = "--exclude";
- static constexpr StringLiteral OPTION_FAILURE_LOGS = "--failure-logs";
- static constexpr StringLiteral OPTION_XUNIT = "--x-xunit";
- static constexpr StringLiteral OPTION_RANDOMIZE = "--x-randomize";
+ static constexpr StringLiteral OPTION_DRY_RUN = "dry-run";
+ static constexpr StringLiteral OPTION_EXCLUDE = "exclude";
+ static constexpr StringLiteral OPTION_FAILURE_LOGS = "failure-logs";
+ static constexpr StringLiteral OPTION_XUNIT = "x-xunit";
+ static constexpr StringLiteral OPTION_RANDOMIZE = "x-randomize";
static constexpr std::array<CommandSetting, 3> CI_SETTINGS = {
{{OPTION_EXCLUDE, "Comma separated list of ports to skip"},
diff --git a/toolsrc/src/vcpkg/commands.contact.cpp b/toolsrc/src/vcpkg/commands.contact.cpp
index fae8e4b56..ce83fab80 100644
--- a/toolsrc/src/vcpkg/commands.contact.cpp
+++ b/toolsrc/src/vcpkg/commands.contact.cpp
@@ -16,7 +16,7 @@ namespace vcpkg::Commands::Contact
return S_EMAIL;
}
- static constexpr StringLiteral OPTION_SURVEY = "--survey";
+ static constexpr StringLiteral OPTION_SURVEY = "survey";
static constexpr std::array<CommandSwitch, 1> SWITCHES = {{
{OPTION_SURVEY, "Launch default browser to the current vcpkg survey"},
diff --git a/toolsrc/src/vcpkg/commands.dependinfo.cpp b/toolsrc/src/vcpkg/commands.dependinfo.cpp
index a6695cf2d..ba6da1aa3 100644
--- a/toolsrc/src/vcpkg/commands.dependinfo.cpp
+++ b/toolsrc/src/vcpkg/commands.dependinfo.cpp
@@ -21,11 +21,11 @@ namespace vcpkg::Commands::DependInfo
{
namespace
{
- constexpr StringLiteral OPTION_DOT = "--dot";
- constexpr StringLiteral OPTION_DGML = "--dgml";
- constexpr StringLiteral OPTION_SHOW_DEPTH = "--show-depth";
- constexpr StringLiteral OPTION_MAX_RECURSE = "--max-recurse";
- constexpr StringLiteral OPTION_SORT = "--sort";
+ constexpr StringLiteral OPTION_DOT = "dot";
+ constexpr StringLiteral OPTION_DGML = "dgml";
+ constexpr StringLiteral OPTION_SHOW_DEPTH = "show-depth";
+ constexpr StringLiteral OPTION_MAX_RECURSE = "max-recurse";
+ constexpr StringLiteral OPTION_SORT = "sort";
constexpr int NO_RECURSE_LIMIT_VALUE = -1;
diff --git a/toolsrc/src/vcpkg/commands.edit.cpp b/toolsrc/src/vcpkg/commands.edit.cpp
index cd3ae6c4a..a433af8ec 100644
--- a/toolsrc/src/vcpkg/commands.edit.cpp
+++ b/toolsrc/src/vcpkg/commands.edit.cpp
@@ -80,9 +80,9 @@ namespace
namespace vcpkg::Commands::Edit
{
- static constexpr StringLiteral OPTION_BUILDTREES = "--buildtrees";
+ static constexpr StringLiteral OPTION_BUILDTREES = "buildtrees";
- static constexpr StringLiteral OPTION_ALL = "--all";
+ static constexpr StringLiteral OPTION_ALL = "all";
static std::vector<std::string> valid_arguments(const VcpkgPaths& paths)
{
diff --git a/toolsrc/src/vcpkg/commands.env.cpp b/toolsrc/src/vcpkg/commands.env.cpp
index 8cf264d17..bcde99166 100644
--- a/toolsrc/src/vcpkg/commands.env.cpp
+++ b/toolsrc/src/vcpkg/commands.env.cpp
@@ -10,11 +10,11 @@
namespace vcpkg::Commands::Env
{
- static constexpr StringLiteral OPTION_BIN = "--bin";
- static constexpr StringLiteral OPTION_INCLUDE = "--include";
- static constexpr StringLiteral OPTION_DEBUG_BIN = "--debug-bin";
- static constexpr StringLiteral OPTION_TOOLS = "--tools";
- static constexpr StringLiteral OPTION_PYTHON = "--python";
+ static constexpr StringLiteral OPTION_BIN = "bin";
+ static constexpr StringLiteral OPTION_INCLUDE = "include";
+ static constexpr StringLiteral OPTION_DEBUG_BIN = "debug-bin";
+ static constexpr StringLiteral OPTION_TOOLS = "tools";
+ static constexpr StringLiteral OPTION_PYTHON = "python";
static constexpr std::array<CommandSwitch, 5> SWITCHES = {{
{OPTION_BIN, "Add installed bin/ to PATH"},
diff --git a/toolsrc/src/vcpkg/commands.format-manifest.cpp b/toolsrc/src/vcpkg/commands.format-manifest.cpp
index b338b5d15..f23472245 100644
--- a/toolsrc/src/vcpkg/commands.format-manifest.cpp
+++ b/toolsrc/src/vcpkg/commands.format-manifest.cpp
@@ -10,7 +10,7 @@
namespace vcpkg::Commands::FormatManifest
{
- static constexpr StringLiteral OPTION_ALL = "--all";
+ static constexpr StringLiteral OPTION_ALL = "all";
const CommandSwitch FORMAT_SWITCHES[] = {{OPTION_ALL, "Format all ports' manifest files."}};
diff --git a/toolsrc/src/vcpkg/commands.list.cpp b/toolsrc/src/vcpkg/commands.list.cpp
index 6e4156aa8..cb57e056f 100644
--- a/toolsrc/src/vcpkg/commands.list.cpp
+++ b/toolsrc/src/vcpkg/commands.list.cpp
@@ -9,8 +9,7 @@
namespace vcpkg::Commands::List
{
- static constexpr StringLiteral OPTION_FULLDESC =
- "--x-full-desc"; // TODO: This should find a better home, eventually
+ static constexpr StringLiteral OPTION_FULLDESC = "x-full-desc"; // TODO: This should find a better home, eventually
static void do_print(const StatusParagraph& pgh, const bool full_desc)
{
diff --git a/toolsrc/src/vcpkg/commands.search.cpp b/toolsrc/src/vcpkg/commands.search.cpp
index 3d9fe58bb..b78420b4d 100644
--- a/toolsrc/src/vcpkg/commands.search.cpp
+++ b/toolsrc/src/vcpkg/commands.search.cpp
@@ -15,8 +15,7 @@ using vcpkg::PortFileProvider::PathsPortFileProvider;
namespace vcpkg::Commands::Search
{
- static constexpr StringLiteral OPTION_FULLDESC =
- "--x-full-desc"; // TODO: This should find a better home, eventually
+ static constexpr StringLiteral OPTION_FULLDESC = "x-full-desc"; // TODO: This should find a better home, eventually
static void do_print(const SourceParagraph& source_paragraph, bool full_desc)
{
diff --git a/toolsrc/src/vcpkg/commands.setinstalled.cpp b/toolsrc/src/vcpkg/commands.setinstalled.cpp
index c7c22a774..82e1c763f 100644
--- a/toolsrc/src/vcpkg/commands.setinstalled.cpp
+++ b/toolsrc/src/vcpkg/commands.setinstalled.cpp
@@ -14,8 +14,8 @@
namespace vcpkg::Commands::SetInstalled
{
- static constexpr StringLiteral OPTION_DRY_RUN = "--dry-run";
- static constexpr StringLiteral OPTION_WRITE_PACKAGES_CONFIG = "--x-write-nuget-packages-config";
+ static constexpr StringLiteral OPTION_DRY_RUN = "dry-run";
+ static constexpr StringLiteral OPTION_WRITE_PACKAGES_CONFIG = "x-write-nuget-packages-config";
static constexpr CommandSwitch INSTALL_SWITCHES[] = {
{OPTION_DRY_RUN, "Do not actually build or install"},
diff --git a/toolsrc/src/vcpkg/commands.upgrade.cpp b/toolsrc/src/vcpkg/commands.upgrade.cpp
index d1fa13eac..25fb0de98 100644
--- a/toolsrc/src/vcpkg/commands.upgrade.cpp
+++ b/toolsrc/src/vcpkg/commands.upgrade.cpp
@@ -19,8 +19,8 @@ namespace vcpkg::Commands::Upgrade
using Install::KeepGoing;
using Install::to_keep_going;
- static constexpr StringLiteral OPTION_NO_DRY_RUN = "--no-dry-run";
- static constexpr StringLiteral OPTION_KEEP_GOING = "--keep-going";
+ static constexpr StringLiteral OPTION_NO_DRY_RUN = "no-dry-run";
+ static constexpr StringLiteral OPTION_KEEP_GOING = "keep-going";
static constexpr std::array<CommandSwitch, 2> INSTALL_SWITCHES = {{
{OPTION_NO_DRY_RUN, "Actually upgrade"},
diff --git a/toolsrc/src/vcpkg/export.chocolatey.cpp b/toolsrc/src/vcpkg/export.chocolatey.cpp
index b5a0a0a88..40564ae13 100644
--- a/toolsrc/src/vcpkg/export.chocolatey.cpp
+++ b/toolsrc/src/vcpkg/export.chocolatey.cpp
@@ -114,7 +114,7 @@ Get-Content $whereToInstallCache | Foreach-Object {
}
$installedDir = Join-Path $whereToInstall 'installed'
-Get-Content $listFile | Foreach-Object {
+Get-Content $listFile | Foreach-Object {
$fileToRemove = Join-Path $installedDir $_
if (Test-Path $fileToRemove -PathType Leaf) {
Remove-Item $fileToRemove
diff --git a/toolsrc/src/vcpkg/export.cpp b/toolsrc/src/vcpkg/export.cpp
index 2b3010dc3..54a1180c1 100644
--- a/toolsrc/src/vcpkg/export.cpp
+++ b/toolsrc/src/vcpkg/export.cpp
@@ -272,33 +272,33 @@ namespace vcpkg::Export
std::vector<PackageSpec> specs;
};
- static constexpr StringLiteral OPTION_OUTPUT = "--output";
- static constexpr StringLiteral OPTION_DRY_RUN = "--dry-run";
- static constexpr StringLiteral OPTION_RAW = "--raw";
- static constexpr StringLiteral OPTION_NUGET = "--nuget";
- static constexpr StringLiteral OPTION_IFW = "--ifw";
- static constexpr StringLiteral OPTION_ZIP = "--zip";
- static constexpr StringLiteral OPTION_SEVEN_ZIP = "--7zip";
- static constexpr StringLiteral OPTION_NUGET_ID = "--nuget-id";
- static constexpr StringLiteral OPTION_NUGET_VERSION = "--nuget-version";
- static constexpr StringLiteral OPTION_IFW_REPOSITORY_URL = "--ifw-repository-url";
- static constexpr StringLiteral OPTION_IFW_PACKAGES_DIR_PATH = "--ifw-packages-directory-path";
- static constexpr StringLiteral OPTION_IFW_REPOSITORY_DIR_PATH = "--ifw-repository-directory-path";
- static constexpr StringLiteral OPTION_IFW_CONFIG_FILE_PATH = "--ifw-configuration-file-path";
- static constexpr StringLiteral OPTION_IFW_INSTALLER_FILE_PATH = "--ifw-installer-file-path";
- static constexpr StringLiteral OPTION_CHOCOLATEY = "--x-chocolatey";
- static constexpr StringLiteral OPTION_CHOCOLATEY_MAINTAINER = "--x-maintainer";
- static constexpr StringLiteral OPTION_CHOCOLATEY_VERSION_SUFFIX = "--x-version-suffix";
- static constexpr StringLiteral OPTION_ALL_INSTALLED = "--x-all-installed";
-
- static constexpr StringLiteral OPTION_PREFAB = "--prefab";
- static constexpr StringLiteral OPTION_PREFAB_GROUP_ID = "--prefab-group-id";
- static constexpr StringLiteral OPTION_PREFAB_ARTIFACT_ID = "--prefab-artifact-id";
- static constexpr StringLiteral OPTION_PREFAB_VERSION = "--prefab-version";
- static constexpr StringLiteral OPTION_PREFAB_SDK_MIN_VERSION = "--prefab-min-sdk";
- static constexpr StringLiteral OPTION_PREFAB_SDK_TARGET_VERSION = "--prefab-target-sdk";
- static constexpr StringLiteral OPTION_PREFAB_ENABLE_MAVEN = "--prefab-maven";
- static constexpr StringLiteral OPTION_PREFAB_ENABLE_DEBUG = "--prefab-debug";
+ static constexpr StringLiteral OPTION_OUTPUT = "output";
+ static constexpr StringLiteral OPTION_DRY_RUN = "dry-run";
+ static constexpr StringLiteral OPTION_RAW = "raw";
+ static constexpr StringLiteral OPTION_NUGET = "nuget";
+ static constexpr StringLiteral OPTION_IFW = "ifw";
+ static constexpr StringLiteral OPTION_ZIP = "zip";
+ static constexpr StringLiteral OPTION_SEVEN_ZIP = "7zip";
+ static constexpr StringLiteral OPTION_NUGET_ID = "nuget-id";
+ static constexpr StringLiteral OPTION_NUGET_VERSION = "nuget-version";
+ static constexpr StringLiteral OPTION_IFW_REPOSITORY_URL = "ifw-repository-url";
+ static constexpr StringLiteral OPTION_IFW_PACKAGES_DIR_PATH = "ifw-packages-directory-path";
+ static constexpr StringLiteral OPTION_IFW_REPOSITORY_DIR_PATH = "ifw-repository-directory-path";
+ static constexpr StringLiteral OPTION_IFW_CONFIG_FILE_PATH = "ifw-configuration-file-path";
+ static constexpr StringLiteral OPTION_IFW_INSTALLER_FILE_PATH = "ifw-installer-file-path";
+ static constexpr StringLiteral OPTION_CHOCOLATEY = "x-chocolatey";
+ static constexpr StringLiteral OPTION_CHOCOLATEY_MAINTAINER = "x-maintainer";
+ static constexpr StringLiteral OPTION_CHOCOLATEY_VERSION_SUFFIX = "x-version-suffix";
+ static constexpr StringLiteral OPTION_ALL_INSTALLED = "x-all-installed";
+
+ static constexpr StringLiteral OPTION_PREFAB = "prefab";
+ static constexpr StringLiteral OPTION_PREFAB_GROUP_ID = "prefab-group-id";
+ static constexpr StringLiteral OPTION_PREFAB_ARTIFACT_ID = "prefab-artifact-id";
+ static constexpr StringLiteral OPTION_PREFAB_VERSION = "prefab-version";
+ static constexpr StringLiteral OPTION_PREFAB_SDK_MIN_VERSION = "prefab-min-sdk";
+ static constexpr StringLiteral OPTION_PREFAB_SDK_TARGET_VERSION = "prefab-target-sdk";
+ static constexpr StringLiteral OPTION_PREFAB_ENABLE_MAVEN = "prefab-maven";
+ static constexpr StringLiteral OPTION_PREFAB_ENABLE_DEBUG = "prefab-debug";
static constexpr std::array<CommandSwitch, 11> EXPORT_SWITCHES = {{
{OPTION_DRY_RUN, "Do not actually export"},
diff --git a/toolsrc/src/vcpkg/install.cpp b/toolsrc/src/vcpkg/install.cpp
index 0767a1bc7..da4248c39 100644
--- a/toolsrc/src/vcpkg/install.cpp
+++ b/toolsrc/src/vcpkg/install.cpp
@@ -501,17 +501,17 @@ namespace vcpkg::Install
return InstallSummary{std::move(results), timer.to_string()};
}
- static constexpr StringLiteral OPTION_DRY_RUN = "--dry-run";
- static constexpr StringLiteral OPTION_USE_HEAD_VERSION = "--head";
- static constexpr StringLiteral OPTION_NO_DOWNLOADS = "--no-downloads";
- static constexpr StringLiteral OPTION_ONLY_DOWNLOADS = "--only-downloads";
- static constexpr StringLiteral OPTION_RECURSE = "--recurse";
- static constexpr StringLiteral OPTION_KEEP_GOING = "--keep-going";
- static constexpr StringLiteral OPTION_EDITABLE = "--editable";
- static constexpr StringLiteral OPTION_XUNIT = "--x-xunit";
- static constexpr StringLiteral OPTION_USE_ARIA2 = "--x-use-aria2";
- static constexpr StringLiteral OPTION_CLEAN_AFTER_BUILD = "--clean-after-build";
- static constexpr StringLiteral OPTION_WRITE_PACKAGES_CONFIG = "--x-write-nuget-packages-config";
+ static constexpr StringLiteral OPTION_DRY_RUN = "dry-run";
+ static constexpr StringLiteral OPTION_USE_HEAD_VERSION = "head";
+ static constexpr StringLiteral OPTION_NO_DOWNLOADS = "no-downloads";
+ static constexpr StringLiteral OPTION_ONLY_DOWNLOADS = "only-downloads";
+ static constexpr StringLiteral OPTION_RECURSE = "recurse";
+ static constexpr StringLiteral OPTION_KEEP_GOING = "keep-going";
+ static constexpr StringLiteral OPTION_EDITABLE = "editable";
+ static constexpr StringLiteral OPTION_XUNIT = "x-xunit";
+ static constexpr StringLiteral OPTION_USE_ARIA2 = "x-use-aria2";
+ static constexpr StringLiteral OPTION_CLEAN_AFTER_BUILD = "clean-after-build";
+ static constexpr StringLiteral OPTION_WRITE_PACKAGES_CONFIG = "x-write-nuget-packages-config";
static constexpr std::array<CommandSwitch, 9> INSTALL_SWITCHES = {{
{OPTION_DRY_RUN, "Do not actually build or install"},
diff --git a/toolsrc/src/vcpkg/remove.cpp b/toolsrc/src/vcpkg/remove.cpp
index 84077ff44..62e203b43 100644
--- a/toolsrc/src/vcpkg/remove.cpp
+++ b/toolsrc/src/vcpkg/remove.cpp
@@ -184,11 +184,11 @@ namespace vcpkg::Remove
}
}
- static constexpr StringLiteral OPTION_PURGE = "--purge";
- static constexpr StringLiteral OPTION_NO_PURGE = "--no-purge";
- static constexpr StringLiteral OPTION_RECURSE = "--recurse";
- static constexpr StringLiteral OPTION_DRY_RUN = "--dry-run";
- static constexpr StringLiteral OPTION_OUTDATED = "--outdated";
+ static constexpr StringLiteral OPTION_PURGE = "purge";
+ static constexpr StringLiteral OPTION_NO_PURGE = "no-purge";
+ static constexpr StringLiteral OPTION_RECURSE = "recurse";
+ static constexpr StringLiteral OPTION_DRY_RUN = "dry-run";
+ static constexpr StringLiteral OPTION_OUTDATED = "outdated";
static constexpr std::array<CommandSwitch, 5> SWITCHES = {{
{OPTION_PURGE, "Remove the cached copy of the package (default)"},
diff --git a/toolsrc/src/vcpkg/vcpkgcmdarguments.cpp b/toolsrc/src/vcpkg/vcpkgcmdarguments.cpp
index 6cfbd43f8..280faae0d 100644
--- a/toolsrc/src/vcpkg/vcpkgcmdarguments.cpp
+++ b/toolsrc/src/vcpkg/vcpkgcmdarguments.cpp
@@ -177,12 +177,9 @@ namespace vcpkg
}
// returns true if this does parse this argument as this option
- // REQUIRES: Strings::starts_with(argument, "--");
template<class T, class F>
- static bool try_parse_argument_as_option(StringView option, StringView argument, T& place, F parser)
+ static bool try_parse_argument_as_option(StringView option, StringView arg, T& place, F parser)
{
- // remove the first two '-'s
- auto arg = argument.substr(2);
if (arg.size() <= option.size() + 1)
{
// it is impossible for this argument to be this option
@@ -215,13 +212,9 @@ namespace vcpkg
}
// returns true if this does parse this argument as this option
- // REQUIRES: Strings::starts_with(argument, "--");
template<class T>
- static bool try_parse_argument_as_switch(StringView option, StringView argument, T& place)
+ static bool try_parse_argument_as_switch(StringView option, StringView arg, T& place)
{
- // remove the first two '-'s
- auto arg = argument.substr(2);
-
if (equals_modulo_experimental(arg, option))
{
parse_switch(true, option, place);
@@ -245,45 +238,46 @@ namespace vcpkg
for (auto it = arg_begin; it != arg_end; ++it)
{
- std::string arg = *it;
+ std::string basic_arg = *it;
- if (arg.empty())
+ if (basic_arg.empty())
{
continue;
}
- if (arg.size() >= 2 && arg[0] == '-' && arg[1] != '-')
+ if (basic_arg.size() >= 2 && basic_arg[0] == '-' && basic_arg[1] != '-')
{
Metrics::g_metrics.lock()->track_property("error", "error short options are not supported");
- Checks::exit_with_message(VCPKG_LINE_INFO, "Error: short options are not supported: %s", arg);
+ Checks::exit_with_message(VCPKG_LINE_INFO, "Error: short options are not supported: %s", basic_arg);
}
- if (arg.size() < 2 || arg[0] != '-')
+ if (basic_arg.size() < 2 || basic_arg[0] != '-')
{
if (args.command.empty())
{
- args.command = std::move(arg);
+ args.command = std::move(basic_arg);
}
else
{
- args.command_arguments.push_back(std::move(arg));
+ args.command_arguments.push_back(std::move(basic_arg));
}
continue;
}
- // arg[0] == '-' && arg[1] == '-'
// make argument case insensitive before the first =
- auto first_eq = std::find(std::begin(arg), std::end(arg), '=');
- Strings::ascii_to_lowercase(std::begin(arg), first_eq);
+ auto first_eq = std::find(std::begin(basic_arg), std::end(basic_arg), '=');
+ Strings::ascii_to_lowercase(std::begin(basic_arg), first_eq);
+ // basic_arg[0] == '-' && basic_arg[1] == '-'
+ StringView arg = StringView(basic_arg).substr(2);
// command switch
- if (arg.substr(2) == VCPKG_ROOT_DIR_ARG)
+ if (arg == VCPKG_ROOT_DIR_ARG)
{
++it;
parse_value(it, arg_end, VCPKG_ROOT_DIR_ARG, args.vcpkg_root_dir);
continue;
}
- if (arg.substr(2) == TRIPLET_ARG)
+ if (arg == TRIPLET_ARG)
{
++it;
parse_value(it, arg_end, TRIPLET_ARG, args.triplet);
@@ -353,28 +347,17 @@ namespace vcpkg
}
if (found) continue;
- const auto eq_pos = arg.find('=');
- if (eq_pos != std::string::npos)
+ const auto eq_pos = std::find(arg.begin(), arg.end(), '=');
+ if (eq_pos != arg.end())
{
- const auto& key = arg.substr(0, eq_pos);
- const auto& value = arg.substr(eq_pos + 1);
+ const auto& key = StringView(arg.begin(), eq_pos);
+ const auto& value = StringView(eq_pos + 1, arg.end());
- auto key_it = args.optional_command_arguments.find(key);
- if (key_it == args.optional_command_arguments.end())
- {
- args.optional_command_arguments.emplace(key, std::vector<std::string>{value});
- }
- else
- {
- if (auto* maybe_values = key_it->second.get())
- {
- maybe_values->emplace_back(value);
- }
- }
+ args.command_options[key.to_string()].push_back(value.to_string());
}
else
{
- args.optional_command_arguments.emplace(arg, nullopt);
+ args.command_switches.insert(arg.to_string());
}
}
@@ -424,104 +407,123 @@ namespace vcpkg
}
}
- auto options_copy = this->optional_command_arguments;
- for (auto&& option : command_structure.options.switches)
+ auto switches_copy = this->command_switches;
+ auto options_copy = this->command_options;
+
+ const auto find_option = [](const auto& set, StringLiteral name) {
+ auto it = set.find(name);
+ if (it == set.end() && !Strings::starts_with(name, "x-"))
+ {
+ it = set.find(Strings::format("x-%s", name));
+ }
+
+ return it;
+ };
+
+ for (const auto& switch_ : command_structure.options.switches)
{
- const auto it = options_copy.find(option.name);
+ const auto it = find_option(switches_copy, switch_.name);
+ if (it != switches_copy.end())
+ {
+ output.switches.insert(switch_.name);
+ switches_copy.erase(it);
+ }
+ const auto option_it = find_option(options_copy, switch_.name);
+ if (option_it != options_copy.end())
+ {
+ // This means that the switch was passed like '--a=xyz'
+ System::printf(
+ System::Color::error, "Error: The option '--%s' does not accept an argument.\n", switch_.name);
+ options_copy.erase(option_it);
+ failed = true;
+ }
+ }
+
+ for (const auto& option : command_structure.options.settings)
+ {
+ const auto it = find_option(options_copy, option.name);
if (it != options_copy.end())
{
- if (it->second.has_value())
+ const auto& value = it->second;
+ if (value.empty())
+ {
+ Checks::unreachable(VCPKG_LINE_INFO);
+ }
+
+ if (value.size() > 1)
{
- // Having a string value indicates it was passed like '--a=xyz'
System::printf(
- System::Color::error, "Error: The option '%s' does not accept an argument.\n", option.name);
+ System::Color::error, "Error: The option '%s' can only be passed once.\n", option.name);
+ failed = true;
+ }
+ else if (value.front().empty())
+ {
+ // Fail when not given a value, e.g.: "vcpkg install sqlite3 --additional-ports="
+ System::printf(System::Color::error,
+ "Error: The option '--%s' must be passed a non-empty argument.\n",
+ option.name);
failed = true;
}
else
{
- output.switches.insert(option.name);
+ output.settings.emplace(option.name, value.front());
options_copy.erase(it);
}
}
+ const auto switch_it = find_option(switches_copy, option.name);
+ if (switch_it != switches_copy.end())
+ {
+ // This means that the option was passed like '--a'
+ System::printf(
+ System::Color::error, "Error: The option '--%s' must be passed an argument.\n", option.name);
+ switches_copy.erase(switch_it);
+ failed = true;
+ }
}
- for (auto&& option : command_structure.options.settings)
+ for (const auto& option : command_structure.options.multisettings)
{
- const auto it = options_copy.find(option.name);
+ const auto it = find_option(options_copy, option.name);
if (it != options_copy.end())
{
- if (!it->second.has_value())
- {
- // Not having a string value indicates it was passed like '--a'
- System::printf(
- System::Color::error, "Error: The option '%s' must be passed an argument.\n", option.name);
- failed = true;
- }
- else
+ const auto& value = it->second;
+ for (const auto& v : value)
{
- const auto& value = it->second.value_or_exit(VCPKG_LINE_INFO);
- if (value.front().empty())
+ if (v.empty())
{
- // Fail when not given a value, e.g.: "vcpkg install sqlite3 --additional-ports="
- System::printf(
- System::Color::error, "Error: The option '%s' must be passed an argument.\n", option.name);
- failed = true;
- }
- else if (value.size() > 1)
- {
- System::printf(
- System::Color::error, "Error: The option '%s' can only be passed once.\n", option.name);
+ System::printf(System::Color::error,
+ "Error: The option '--%s' must be passed non-empty arguments.\n",
+ option.name);
failed = true;
}
else
{
- output.settings.emplace(option.name, value.front());
- options_copy.erase(it);
+ output.multisettings[option.name].push_back(v);
}
}
+ options_copy.erase(it);
}
- }
-
- for (auto&& option : command_structure.options.multisettings)
- {
- const auto it = options_copy.find(option.name);
- if (it != options_copy.end())
+ const auto switch_it = find_option(switches_copy, option.name);
+ if (switch_it != switches_copy.end())
{
- if (!it->second.has_value())
- {
- // Not having a string value indicates it was passed like '--a'
- System::printf(
- System::Color::error, "Error: The option '%s' must be passed an argument.\n", option.name);
- failed = true;
- }
- else
- {
- const auto& value = it->second.value_or_exit(VCPKG_LINE_INFO);
- for (auto&& v : value)
- {
- if (v.empty())
- {
- System::printf(System::Color::error,
- "Error: The option '%s' must be passed an argument.\n",
- option.name);
- failed = true;
- }
- else
- {
- output.multisettings[option.name].emplace_back(v);
- }
- }
- options_copy.erase(it);
- }
+ // This means that the option was passed like '--a'
+ System::printf(
+ System::Color::error, "Error: The option '--%s' must be passed an argument.\n", option.name);
+ switches_copy.erase(switch_it);
+ failed = true;
}
}
- if (!options_copy.empty())
+ if (!switches_copy.empty())
{
System::printf(System::Color::error, "Unknown option(s) for command '%s':\n", this->command);
+ for (auto&& switch_ : switches_copy)
+ {
+ System::print2(" '--", switch_, "'\n");
+ }
for (auto&& option : options_copy)
{
- System::print2(" '", option.first, "'\n");
+ System::print2(" '--", option.first, "'\n");
}
System::print2("\n");
failed = true;
@@ -585,15 +587,15 @@ namespace vcpkg
table.header("Options");
for (auto&& option : command_structure.options.switches)
{
- table.format(option.name, option.short_help_text);
+ table.format(Strings::format("--%s", option.name), option.short_help_text);
}
for (auto&& option : command_structure.options.settings)
{
- table.format((option.name + "=..."), option.short_help_text);
+ table.format(Strings::format("--%s=...", option.name), option.short_help_text);
}
for (auto&& option : command_structure.options.multisettings)
{
- table.format((option.name + "=..."), option.short_help_text);
+ table.format(Strings::format("--%s=...", option.name), option.short_help_text);
}
VcpkgCmdArguments::append_common_options(table);