This is an automated email from the ASF dual-hosted git repository.
wangdan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-pegasus.git
The following commit(s) were added to refs/heads/master by this push:
new 8fd89029c fix(shell): Add PARSE_OPT_STRS marco for shell command
execute flag input mode (#2040)
8fd89029c is described below
commit 8fd89029c8b68098c28144754de370ab68cb0ff8
Author: Samunroyu <[email protected]>
AuthorDate: Wed Jun 5 16:45:01 2024 +0800
fix(shell): Add PARSE_OPT_STRS marco for shell command execute flag input
mode (#2040)
The marco `PARSE_STRS` execute strs with `param_index`,and it only
execute the number of params_index of input strs.
The marco `PARSE_OPT_STRS` can execute input strs with flag.
The historical flag input mode should be continued.
---
src/shell/command_helper.h | 6 ++++++
src/shell/commands/cold_backup.cpp | 23 +++++++++++++++++++----
2 files changed, 25 insertions(+), 4 deletions(-)
diff --git a/src/shell/command_helper.h b/src/shell/command_helper.h
index 965eb64df..250e28fec 100644
--- a/src/shell/command_helper.h
+++ b/src/shell/command_helper.h
@@ -929,6 +929,12 @@ private:
}
\
} while (false)
+#define PARSE_OPT_STRS(container, def_val, ...)
\
+ do {
\
+ const auto param = cmd(__VA_ARGS__, (def_val)).str();
\
+ ::dsn::utils::split_args(param.c_str(), container, ',');
\
+ } while (false)
+
// A helper macro to parse command argument, the result is filled in an
uint32_t variable named
// 'value'.
#define PARSE_UINT(value)
\
diff --git a/src/shell/commands/cold_backup.cpp
b/src/shell/commands/cold_backup.cpp
index f235234c6..35cc2ff2e 100644
--- a/src/shell/commands/cold_backup.cpp
+++ b/src/shell/commands/cold_backup.cpp
@@ -27,7 +27,9 @@
#include <algorithm>
#include <cstdint>
#include <iostream>
+#include <map>
#include <memory>
+#include <set>
#include <string>
#include <vector>
@@ -157,15 +159,28 @@ bool ls_backup_policy(command_executor *e, shell_context
*sc, arguments args)
bool query_backup_policy(command_executor *e, shell_context *sc, arguments
args)
{
- const std::string query_backup_policy_help = "<policy_name>
[-b|--backup_info_cnt] [-j|--json]";
+ const std::string query_backup_policy_help =
+ "<-p|--policy_name> [-b|--backup_info_cnt] [-j|--json]";
argh::parser cmd(args.argc, args.argv,
argh::parser::PREFER_PARAM_FOR_UNREG_OPTION);
- RETURN_FALSE_IF_NOT(cmd.pos_args().size() > 1,
+ RETURN_FALSE_IF_NOT(cmd.params().size() >= 1,
"invalid command, should be in the form of '{}'",
query_backup_policy_help);
- int param_index = 1;
std::vector<std::string> policy_names;
- PARSE_STRS(policy_names);
+ PARSE_OPT_STRS(policy_names, "", {"-p", "--policy_name"});
+
+ if (policy_names.empty()) {
+ SHELL_PRINTLN_ERROR(
+ "invalid command, policy_name should be in the form of
'val1,val2,val3' and "
+ "should not be empty");
+ return false;
+ }
+
+ std::set<std::string> str_set(policy_names.begin(), policy_names.end());
+ if (str_set.size() != policy_names.size()) {
+ SHELL_PRINTLN_ERROR("invalid command, policy_name has duplicate
values");
+ return false;
+ }
uint32_t backup_info_cnt;
PARSE_OPT_UINT(backup_info_cnt, 3, {"-b", "--backup_info_cnt"});
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]