diff options
| author | Alexander Karatarakis <alkarata@microsoft.com> | 2017-01-31 13:31:45 -0800 |
|---|---|---|
| committer | Alexander Karatarakis <alkarata@microsoft.com> | 2017-02-01 11:42:41 -0800 |
| commit | bd1a10e5b97b073731cbb97e26611edf317c16d5 (patch) | |
| tree | 0c55b8322c3d6598ebbe67985ee3c2f5a2421c86 /toolsrc/src | |
| parent | f2d40c5b81cba14c86d836bc21978c4f3f691538 (diff) | |
| download | vcpkg-bd1a10e5b97b073731cbb97e26611edf317c16d5.tar.gz vcpkg-bd1a10e5b97b073731cbb97e26611edf317c16d5.zip | |
Enhance the opt_bool type
Diffstat (limited to 'toolsrc/src')
| -rw-r--r-- | toolsrc/src/opt_bool.cpp | 29 | ||||
| -rw-r--r-- | toolsrc/src/vcpkg.cpp | 12 | ||||
| -rw-r--r-- | toolsrc/src/vcpkg_cmd_arguments.cpp | 16 |
3 files changed, 43 insertions, 14 deletions
diff --git a/toolsrc/src/opt_bool.cpp b/toolsrc/src/opt_bool.cpp new file mode 100644 index 000000000..324936fb4 --- /dev/null +++ b/toolsrc/src/opt_bool.cpp @@ -0,0 +1,29 @@ +#include "pch.h" +#include "opt_bool.h" +#include "vcpkg_Checks.h" + +namespace vcpkg::opt_bool +{ + static const std::string UNSPECIFIED_NAME = "unspecified"; + static const std::string ENABLED_NAME = "enabled"; + static const std::string DISABLED_NAME = "disabled"; + type parse(const std::string& s) + { + if (s == UNSPECIFIED_NAME) + { + return opt_bool_t::UNSPECIFIED; + } + + if (s == ENABLED_NAME) + { + return opt_bool_t::ENABLED; + } + + if (s == DISABLED_NAME) + { + return opt_bool_t::DISABLED; + } + + Checks::exit_with_message("Could not convert string [%s] to opt_bool", s); + } +} diff --git a/toolsrc/src/vcpkg.cpp b/toolsrc/src/vcpkg.cpp index 36bd0a40a..3e313c702 100644 --- a/toolsrc/src/vcpkg.cpp +++ b/toolsrc/src/vcpkg.cpp @@ -202,14 +202,14 @@ int wmain(const int argc, const wchar_t* const* const argv) const vcpkg_cmd_arguments args = vcpkg_cmd_arguments::create_from_command_line(argc, argv); - if (args.printmetrics != opt_bool::UNSPECIFIED) - SetPrintMetrics(args.printmetrics == opt_bool::ENABLED); - if (args.sendmetrics != opt_bool::UNSPECIFIED) - SetSendMetrics(args.sendmetrics == opt_bool::ENABLED); + if (args.printmetrics != opt_bool_t::UNSPECIFIED) + SetPrintMetrics(args.printmetrics == opt_bool_t::ENABLED); + if (args.sendmetrics != opt_bool_t::UNSPECIFIED) + SetSendMetrics(args.sendmetrics == opt_bool_t::ENABLED); - if (args.debug != opt_bool::UNSPECIFIED) + if (args.debug != opt_bool_t::UNSPECIFIED) { - g_debugging = (args.debug == opt_bool::ENABLED); + g_debugging = (args.debug == opt_bool_t::ENABLED); } if (g_debugging) diff --git a/toolsrc/src/vcpkg_cmd_arguments.cpp b/toolsrc/src/vcpkg_cmd_arguments.cpp index e0d307077..fdeb6e877 100644 --- a/toolsrc/src/vcpkg_cmd_arguments.cpp +++ b/toolsrc/src/vcpkg_cmd_arguments.cpp @@ -32,11 +32,11 @@ 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"); @@ -94,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; } |
