aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/src/vcpkg_cmd_arguments.cpp
diff options
context:
space:
mode:
authorJan HrubĂ˝ <jhruby.web@gmail.com>2017-03-13 08:56:05 +0100
committerGitHub <noreply@github.com>2017-03-13 08:56:05 +0100
commit665f4118f603c5858217ed7a2f2f824b18ff4fc5 (patch)
treef0167041edf71e90f2331b5025f603392a8de67a /toolsrc/src/vcpkg_cmd_arguments.cpp
parent1bec0fcb73073b5b1719f454c368a63f1bff625e (diff)
parent1c9873a0daf625f67474aaf3e163c592c27ecb65 (diff)
downloadvcpkg-665f4118f603c5858217ed7a2f2f824b18ff4fc5.tar.gz
vcpkg-665f4118f603c5858217ed7a2f2f824b18ff4fc5.zip
Merge pull request #1 from Microsoft/master
pull
Diffstat (limited to 'toolsrc/src/vcpkg_cmd_arguments.cpp')
-rw-r--r--toolsrc/src/vcpkg_cmd_arguments.cpp94
1 files changed, 46 insertions, 48 deletions
diff --git a/toolsrc/src/vcpkg_cmd_arguments.cpp b/toolsrc/src/vcpkg_cmd_arguments.cpp
index ec6946b98..fdeb6e877 100644
--- a/toolsrc/src/vcpkg_cmd_arguments.cpp
+++ b/toolsrc/src/vcpkg_cmd_arguments.cpp
@@ -1,11 +1,7 @@
-#define WIN32_LEAN_AND_MEAN
-#include <Windows.h>
+#include "pch.h"
#include "vcpkg_cmd_arguments.h"
#include "vcpkg_Commands.h"
-#include "vcpkg_Graphs.h"
-#include <unordered_set>
#include "metrics.h"
-#include "vcpkg.h"
#include "vcpkg_System.h"
namespace vcpkg
@@ -20,7 +16,7 @@ namespace vcpkg
{
System::println(System::color::error, "Error: expected value after %s", option_name);
TrackProperty("error", "error option name");
- print_usage();
+ Commands::Help::print_usage();
exit(EXIT_FAILURE);
}
@@ -28,7 +24,7 @@ namespace vcpkg
{
System::println(System::color::error, "Error: %s specified multiple times", option_name);
TrackProperty("error", "error option specified multiple times");
- print_usage();
+ Commands::Help::print_usage();
exit(EXIT_FAILURE);
}
@@ -36,15 +32,15 @@ namespace vcpkg
}
static void parse_switch(
- opt_bool new_setting,
+ opt_bool_t new_setting,
const std::string& option_name,
- opt_bool& option_field)
+ opt_bool_t& option_field)
{
- if (option_field != opt_bool::unspecified && option_field != new_setting)
+ if (option_field != opt_bool_t::UNSPECIFIED && option_field != new_setting)
{
System::println(System::color::error, "Error: conflicting values specified for --%s", option_name);
TrackProperty("error", "error conflicting switches");
- print_usage();
+ Commands::Help::print_usage();
exit(EXIT_FAILURE);
}
option_field = new_setting;
@@ -98,27 +94,27 @@ namespace vcpkg
}
if (arg == "--debug")
{
- parse_switch(opt_bool::enabled, "debug", args.debug);
+ parse_switch(opt_bool_t::ENABLED, "debug", args.debug);
continue;
}
if (arg == "--sendmetrics")
{
- parse_switch(opt_bool::enabled, "sendmetrics", args.sendmetrics);
+ parse_switch(opt_bool_t::ENABLED, "sendmetrics", args.sendmetrics);
continue;
}
if (arg == "--printmetrics")
{
- parse_switch(opt_bool::enabled, "printmetrics", args.printmetrics);
+ parse_switch(opt_bool_t::ENABLED, "printmetrics", args.printmetrics);
continue;
}
if (arg == "--no-sendmetrics")
{
- parse_switch(opt_bool::disabled, "sendmetrics", args.sendmetrics);
+ parse_switch(opt_bool_t::DISABLED, "sendmetrics", args.sendmetrics);
continue;
}
if (arg == "--no-printmetrics")
{
- parse_switch(opt_bool::disabled, "printmetrics", args.printmetrics);
+ parse_switch(opt_bool_t::DISABLED, "printmetrics", args.printmetrics);
continue;
}
@@ -158,7 +154,7 @@ namespace vcpkg
System::println(System::color::error, "Unknown option(s) for command '%s':", this->command);
for (const std::string& option : options_copy)
{
- System::println(option.c_str());
+ System::println(option);
}
exit(EXIT_FAILURE);
}
@@ -166,49 +162,51 @@ namespace vcpkg
return output;
}
- void vcpkg_cmd_arguments::check_max_args(size_t arg_count, const char* example_text) const
+ void vcpkg_cmd_arguments::check_max_arg_count(const size_t expected_arg_count) const
{
- if (command_arguments.size() > arg_count)
+ return check_max_arg_count(expected_arg_count, "");
+ }
+
+ void vcpkg_cmd_arguments::check_min_arg_count(const size_t expected_arg_count) const
+ {
+ return check_min_arg_count(expected_arg_count, "");
+ }
+
+ void vcpkg_cmd_arguments::check_exact_arg_count(const size_t expected_arg_count) const
+ {
+ return check_exact_arg_count(expected_arg_count, "");
+ }
+
+ void vcpkg_cmd_arguments::check_max_arg_count(const size_t expected_arg_count, const std::string& example_text) const
+ {
+ const size_t actual_arg_count = command_arguments.size();
+ if (actual_arg_count > expected_arg_count)
{
- System::println(System::color::error, "Error: too many arguments to command %s", command);
- if (example_text != nullptr)
- print_example(example_text);
- else
- print_usage();
+ System::println(System::color::error, "Error: `%s` requires at most %u arguments, but %u were provided", this->command, expected_arg_count, actual_arg_count);
+ System::print(example_text);
exit(EXIT_FAILURE);
}
}
- std::vector<package_spec> vcpkg_cmd_arguments::parse_all_arguments_as_package_specs(const triplet& default_target_triplet, const char* example_text) const
+ void vcpkg_cmd_arguments::check_min_arg_count(const size_t expected_arg_count, const std::string& example_text) const
{
- size_t arg_count = command_arguments.size();
- if (arg_count < 1)
+ const size_t actual_arg_count = command_arguments.size();
+ if (actual_arg_count < expected_arg_count)
{
- System::println(System::color::error, "Error: %s requires one or more package specifiers", this->command);
- if (example_text == nullptr)
- print_example(Strings::format("%s zlib zlib:x64-windows curl boost", this->command).c_str());
- else
- print_example(example_text);
+ System::println(System::color::error, "Error: `%s` requires at least %u arguments, but %u were provided", this->command, expected_arg_count, actual_arg_count);
+ System::print(example_text);
exit(EXIT_FAILURE);
}
- std::vector<package_spec> specs;
- specs.reserve(arg_count);
+ }
- for (const std::string& command_argument : command_arguments)
+ void vcpkg_cmd_arguments::check_exact_arg_count(const size_t expected_arg_count, const std::string& example_text) const
+ {
+ const size_t actual_arg_count = command_arguments.size();
+ if (actual_arg_count != expected_arg_count)
{
- expected<package_spec> current_spec = package_spec::from_string(command_argument, default_target_triplet);
- if (auto spec = current_spec.get())
- {
- specs.push_back(std::move(*spec));
- }
- else
- {
- System::println(System::color::error, "Error: %s: %s", current_spec.error_code().message(), command_argument);
- print_example(Strings::format("%s zlib:x64-windows", this->command).c_str());
- exit(EXIT_FAILURE);
- }
+ System::println(System::color::error, "Error: `%s` requires %u arguments, but %u were provided", this->command, expected_arg_count, actual_arg_count);
+ System::print(example_text);
+ exit(EXIT_FAILURE);
}
-
- return specs;
}
}