aboutsummaryrefslogtreecommitdiffstats
path: root/src/cli
diff options
context:
space:
mode:
authorRenĂ© Meusel <[email protected]>2022-04-19 13:07:56 +0530
committerRenĂ© Meusel <[email protected]>2022-04-19 14:16:34 +0530
commitadd7ad4c7387ea5bb3eab7b66798e95e950e3b55 (patch)
tree8ac3c664fdaf16c8352a1430b559f3d3e3d9c9fc /src/cli
parent225cc9a1cbb9b2add45872257909c177ff97a80f (diff)
add CLI Command::get_arg_maybe()
Diffstat (limited to 'src/cli')
-rw-r--r--src/cli/cli.cpp9
-rw-r--r--src/cli/cli.h6
2 files changed, 15 insertions, 0 deletions
diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp
index e58f1a68d..8cf2de99e 100644
--- a/src/cli/cli.cpp
+++ b/src/cli/cli.cpp
@@ -128,6 +128,15 @@ std::string Command::get_arg_or(const std::string& opt_name, const std::string&
return m_args->get_arg_or(opt_name, otherwise);
}
+std::optional<std::string> Command::get_arg_maybe(const std::string& opt_name) const
+ {
+ auto arg = m_args->get_arg(opt_name);
+ if(arg.empty())
+ return std::nullopt;
+ else
+ return arg;
+ }
+
size_t Command::get_arg_sz(const std::string& opt_name) const
{
return m_args->get_arg_sz(opt_name);
diff --git a/src/cli/cli.h b/src/cli/cli.h
index b7f81277d..2f2080ea9 100644
--- a/src/cli/cli.h
+++ b/src/cli/cli.h
@@ -10,6 +10,7 @@
#include <botan/build.h>
#include <functional>
#include <ostream>
+#include <optional>
#include <map>
#include <memory>
#include <string>
@@ -146,6 +147,11 @@ class Command
*/
std::string get_arg_or(const std::string& opt_name, const std::string& otherwise) const;
+ /*
+ * Like get_arg() but if the argument was not specified or is empty, returns std::nullopt
+ */
+ std::optional<std::string> get_arg_maybe(const std::string& opt_name) const;
+
size_t get_arg_sz(const std::string& opt_name) const;
uint16_t get_arg_u16(const std::string& opt_name) const;