From e9301577ee22cd66aea3f417afe30a6f8af6067c Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Fri, 11 Oct 2019 13:19:32 -0700 Subject: [PATCH] rgw-admin: cmdline, use generic std::any to hold value Signed-off-by: Yehuda Sadeh --- src/rgw/rgw_admin.cc | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc index eda958dd3f431..2eddef052bc9f 100644 --- a/src/rgw/rgw_admin.cc +++ b/src/rgw/rgw_admin.cc @@ -403,7 +403,7 @@ class SimpleCmd { public: struct Def { string cmd; - int opt{-1}; + std::any opt; }; using Aliases = std::vector >; @@ -412,7 +412,7 @@ public: private: struct Node { map next; - int opt{-1}; + std::any opt; }; Node cmd_root; @@ -483,12 +483,12 @@ public: template bool find_command(Container& args, - int *opt_cmd, + std::any *opt_cmd, vector *extra_args, string *error) { auto node = &cmd_root; - std::optional found_opt; + std::optional found_opt; for (auto& arg : args) { string norm = normalize_alias(arg); @@ -509,7 +509,7 @@ public: *opt_cmd = found_opt.value_or(node->opt); - if (*opt_cmd < 0) { + if (!opt_cmd->has_value()) { *error ="no command"; return false; } @@ -518,7 +518,7 @@ public: } }; -enum { +enum CMDLINE_OPTS { OPT_NO_CMD = 0, OPT_USER_CREATE, OPT_USER_INFO, @@ -3005,11 +3005,15 @@ int main(int argc, const char **argv) else { std::vector extra_args; - if (!cmd.find_command(args, &opt_cmd, &extra_args, &err)) { + std::any _opt_cmd; + + if (!cmd.find_command(args, &_opt_cmd, &extra_args, &err)) { cerr << err << std::endl; exit(1); } + opt_cmd = std::any_cast(_opt_cmd); + /* some commands may have an optional extra param */ if (!extra_args.empty()) { switch (opt_cmd) { -- 2.39.5