From 3ddec748d087f6effa782c21f7730f02bd92f778 Mon Sep 17 00:00:00 2001 From: songweibin Date: Mon, 19 Nov 2018 19:26:41 +0800 Subject: [PATCH] rbd: fix error parse arg when getting image-meta key Signed-off-by: songweibin --- src/tools/rbd/action/ImageMeta.cc | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/tools/rbd/action/ImageMeta.cc b/src/tools/rbd/action/ImageMeta.cc index f5804de726328..1ea7413d15434 100644 --- a/src/tools/rbd/action/ImageMeta.cc +++ b/src/tools/rbd/action/ImageMeta.cc @@ -24,11 +24,14 @@ void add_key_option(po::options_description *positional) { ("key", "image meta key"); } -int get_key(const po::variables_map &vm, std::string *key) { - *key = utils::get_positional_argument(vm, 1); +int get_key(const po::variables_map &vm, size_t *arg_index, + std::string *key) { + *key = utils::get_positional_argument(vm, *arg_index); if (key->empty()) { std::cerr << "rbd: metadata key was not specified" << std::endl; return -EINVAL; + } else { + ++(*arg_index); } return 0; } @@ -201,7 +204,7 @@ int execute_get(const po::variables_map &vm, } std::string key; - r = get_key(vm, &key); + r = get_key(vm, &arg_index, &key); if (r < 0) { return r; } @@ -248,7 +251,7 @@ int execute_set(const po::variables_map &vm, } std::string key; - r = get_key(vm, &key); + r = get_key(vm, &arg_index, &key); if (r < 0) { return r; } @@ -299,7 +302,7 @@ int execute_remove(const po::variables_map &vm, } std::string key; - r = get_key(vm, &key); + r = get_key(vm, &arg_index, &key); if (r < 0) { return r; } -- 2.39.5