aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Schumacher <roschuma@microsoft.com>2017-10-04 16:24:03 -0700
committerRobert Schumacher <roschuma@microsoft.com>2017-10-04 16:24:03 -0700
commitc98db7541594eadccf6823d4fdde2ff8c53c5fe9 (patch)
tree5d6748c384cb46f0df59ced1f7f8dab4bd983bea
parent1b71053ad9954ffb0cb3c2955f42a86f62f66372 (diff)
downloadvcpkg-c98db7541594eadccf6823d4fdde2ff8c53c5fe9.tar.gz
vcpkg-c98db7541594eadccf6823d4fdde2ff8c53c5fe9.zip
[vcpkg] Refactor out implication in option parsing for export
-rw-r--r--toolsrc/include/Span.h2
-rw-r--r--toolsrc/src/commands_export.cpp70
2 files changed, 41 insertions, 31 deletions
diff --git a/toolsrc/include/Span.h b/toolsrc/include/Span.h
index b2c9acdbc..a43e8f992 100644
--- a/toolsrc/include/Span.h
+++ b/toolsrc/include/Span.h
@@ -2,6 +2,7 @@
#include <array>
#include <cstddef>
+#include <initializer_list>
#include <vector>
template<class T>
@@ -17,6 +18,7 @@ public:
constexpr Span(std::nullptr_t) noexcept : Span() {}
constexpr Span(T* ptr, size_t count) noexcept : m_ptr(ptr), m_count(count) {}
constexpr Span(T* ptr_begin, T* ptr_end) noexcept : m_ptr(ptr_begin), m_count(ptr_end - ptr_begin) {}
+ constexpr Span(std::initializer_list<T> l) noexcept : m_ptr(l.begin()), m_count(l.size()) {}
template<size_t N>
constexpr Span(T (&arr)[N]) noexcept : Span(arr, N)
diff --git a/toolsrc/src/commands_export.cpp b/toolsrc/src/commands_export.cpp
index a24f2eac7..20838f5a5 100644
--- a/toolsrc/src/commands_export.cpp
+++ b/toolsrc/src/commands_export.cpp
@@ -314,37 +314,45 @@ namespace vcpkg::Commands::Export
Checks::exit_fail(VCPKG_LINE_INFO);
}
- ret.maybe_nuget_id = maybe_lookup(options.settings, OPTION_NUGET_ID);
- ret.maybe_nuget_version = maybe_lookup(options.settings, OPTION_NUGET_VERSION);
-
- Checks::check_exit(VCPKG_LINE_INFO, !ret.maybe_nuget_id || ret.nuget, "--nuget-id is only valid with --nuget");
- Checks::check_exit(
- VCPKG_LINE_INFO, !ret.maybe_nuget_version || ret.nuget, "--nuget-version is only valid with --nuget");
-
- ret.ifw_options.maybe_repository_url = maybe_lookup(options.settings, OPTION_IFW_REPOSITORY_URL);
- Checks::check_exit(VCPKG_LINE_INFO,
- !ret.ifw_options.maybe_repository_url || ret.ifw,
- "--ifw-repository-url is only valid with --ifw");
-
- ret.ifw_options.maybe_packages_dir_path = maybe_lookup(options.settings, OPTION_IFW_PACKAGES_DIR_PATH);
- Checks::check_exit(VCPKG_LINE_INFO,
- !ret.ifw_options.maybe_packages_dir_path || ret.ifw,
- "--ifw-packages-directory-path is only valid with --ifw");
-
- ret.ifw_options.maybe_repository_dir_path = maybe_lookup(options.settings, OPTION_IFW_REPOSITORY_DIR_PATH);
- Checks::check_exit(VCPKG_LINE_INFO,
- !ret.ifw_options.maybe_repository_dir_path || ret.ifw,
- "--ifw-repository-directory-path is only valid with --ifw");
-
- ret.ifw_options.maybe_config_file_path = maybe_lookup(options.settings, OPTION_IFW_CONFIG_FILE_PATH);
- Checks::check_exit(VCPKG_LINE_INFO,
- !ret.ifw_options.maybe_config_file_path || ret.ifw,
- "--ifw-configuration-file-path is only valid with --ifw");
-
- ret.ifw_options.maybe_installer_file_path = maybe_lookup(options.settings, OPTION_IFW_INSTALLER_FILE_PATH);
- Checks::check_exit(VCPKG_LINE_INFO,
- !ret.ifw_options.maybe_installer_file_path || ret.ifw,
- "--ifw-installer-file-path is only valid with --ifw");
+ struct OptionPair
+ {
+ const std::string& name;
+ Optional<std::string>& out_opt;
+ };
+ const auto options_implies =
+ [&](const std::string& main_opt_name, bool main_opt, Span<const OptionPair> implying_opts) {
+ if (main_opt)
+ {
+ for (auto&& opt : implying_opts)
+ opt.out_opt = maybe_lookup(options.settings, opt.name);
+ }
+ else
+ {
+ for (auto&& opt : implying_opts)
+ Checks::check_exit(VCPKG_LINE_INFO,
+ !maybe_lookup(options.settings, opt.name),
+ "%s is only valid with %s",
+ opt.name,
+ main_opt_name);
+ }
+ };
+
+ options_implies(OPTION_NUGET,
+ ret.nuget,
+ {
+ {OPTION_NUGET_ID, ret.maybe_nuget_id},
+ {OPTION_NUGET_VERSION, ret.maybe_nuget_version},
+ });
+
+ options_implies(OPTION_IFW,
+ ret.ifw,
+ {
+ {OPTION_IFW_REPOSITORY_URL, ret.ifw_options.maybe_repository_url},
+ {OPTION_IFW_PACKAGES_DIR_PATH, ret.ifw_options.maybe_packages_dir_path},
+ {OPTION_IFW_REPOSITORY_DIR_PATH, ret.ifw_options.maybe_repository_dir_path},
+ {OPTION_IFW_CONFIG_FILE_PATH, ret.ifw_options.maybe_config_file_path},
+ {OPTION_IFW_INSTALLER_FILE_PATH, ret.ifw_options.maybe_installer_file_path},
+ });
return ret;
}