From ada42538d2d6a9209280bcbfcd42c1f11eae655d Mon Sep 17 00:00:00 2001 From: Steven Dieffenbach Date: Wed, 8 Jun 2016 15:46:19 -0500 Subject: [PATCH] Added -f flag for formatting to rados command line tool. Fixes: http://tracker.ceph.com/issues/15904 Signed-off-by: Steven Dieffenbach --- src/tools/rados/rados.cc | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/tools/rados/rados.cc b/src/tools/rados/rados.cc index ca20c9b01b8..79d03f8f877 100644 --- a/src/tools/rados/rados.cc +++ b/src/tools/rados/rados.cc @@ -41,6 +41,7 @@ using namespace libradosstriper; #include #include #include +#include #include "cls/lock/cls_lock_client.h" #include "include/compat.h" @@ -3284,12 +3285,36 @@ int main(int argc, const char **argv) argv_to_vec(argc, argv, args); env_to_vec(args); + std::map < std::string, std::string > opts; + std::string val; + + // Necessary to support usage of -f for formatting, + // since global_init will remove the -f using ceph + // argparse procedures. + for (auto j = args.begin(); j != args.end(); ++j) { + if (strcmp(*j, "--") == 0) { + break; + } else if ((j+1) == args.end()) { + // This can't be a formatting call (no format arg) + break; + } else if (strcmp(*j, "-f") == 0) { + val = *(j+1); + unique_ptr formatter(Formatter::create(val.c_str())); + + if (formatter) { + j = args.erase(j); + opts["format"] = val; + + j = args.erase(j); + break; + } + } + } + global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_UTILITY, 0); common_init_finish(g_ceph_context); - std::map < std::string, std::string > opts; std::vector::iterator i; - std::string val; for (i = args.begin(); i != args.end(); ) { if (ceph_argparse_double_dash(args, i)) { break;