aboutsummaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorLee Clagett <code@leeclagett.com>2016-11-25 21:07:45 -0500
committerLee Clagett <code@leeclagett.com>2016-11-25 21:57:27 -0500
commit91ffb61c25561a9143e9a8e713be16b09b03f633 (patch)
treef459cd141f40b861ae861dc80914a162b41d305d /src/common
parentMerge pull request #1372 (diff)
downloadmonero-91ffb61c25561a9143e9a8e713be16b09b03f633.tar.xz
Added command_line::is_yes
Diffstat (limited to 'src/common')
-rw-r--r--src/common/command_line.cpp27
-rw-r--r--src/common/command_line.h3
2 files changed, 29 insertions, 1 deletions
diff --git a/src/common/command_line.cpp b/src/common/command_line.cpp
index b3f488447..28879e098 100644
--- a/src/common/command_line.cpp
+++ b/src/common/command_line.cpp
@@ -29,11 +29,22 @@
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
#include "command_line.h"
-#include "string_tools.h"
+#include <boost/algorithm/string/compare.hpp>
+#include <boost/algorithm/string/predicate.hpp>
+#include "common/i18n.h"
#include "cryptonote_config.h"
+#include "string_tools.h"
namespace command_line
{
+ namespace
+ {
+ const char* tr(const char* str)
+ {
+ return i18n_translate(str, "command_line");
+ }
+ }
+
std::string input_line(const std::string& prompt)
{
std::cout << prompt;
@@ -45,6 +56,20 @@ namespace command_line
}
+ bool is_yes(const std::string& str)
+ {
+ if (str == "y" || str == "Y")
+ return true;
+
+ boost::algorithm::is_iequal ignore_case{};
+ if (boost::algorithm::equals("yes", str, ignore_case))
+ return true;
+ if (boost::algorithm::equals(command_line::tr("yes"), str, ignore_case))
+ return true;
+
+ return false;
+ }
+
const arg_descriptor<bool> arg_help = {"help", "Produce help message"};
const arg_descriptor<bool> arg_version = {"version", "Output version information"};
const arg_descriptor<std::string> arg_data_dir = {"data-dir", "Specify data directory"};
diff --git a/src/common/command_line.h b/src/common/command_line.h
index 0ea749168..98c115bb7 100644
--- a/src/common/command_line.h
+++ b/src/common/command_line.h
@@ -43,6 +43,9 @@ namespace command_line
std::string input_line(const std::string& prompt);
+ //! \return True if `str` is `is_iequal("y" || "yes" || `tr("yes"))`.
+ bool is_yes(const std::string& str);
+
template<typename T, bool required = false>
struct arg_descriptor;