Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mimic: rbd/action: fix error getting positional argument #29294

Merged
merged 2 commits into from Oct 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/tools/rbd/action/ImageMeta.cc
Expand Up @@ -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;
}
Expand Down Expand Up @@ -197,7 +200,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;
}
Expand Down Expand Up @@ -242,12 +245,12 @@ 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;
}

std::string value = utils::get_positional_argument(vm, 2);
std::string value = utils::get_positional_argument(vm, arg_index);
if (value.empty()) {
std::cerr << "rbd: metadata value was not specified" << std::endl;
return -EINVAL;
Expand Down Expand Up @@ -291,7 +294,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;
}
Expand Down
13 changes: 8 additions & 5 deletions src/tools/rbd/action/Lock.cc
Expand Up @@ -24,11 +24,14 @@ void add_id_option(po::options_description *positional) {
("lock-id", "unique lock id");
}

int get_id(const po::variables_map &vm, std::string *id) {
*id = utils::get_positional_argument(vm, 1);
int get_id(const po::variables_map &vm, size_t *arg_index,
std::string *id) {
*id = utils::get_positional_argument(vm, *arg_index);
if (id->empty()) {
std::cerr << "rbd: lock id was not specified" << std::endl;
return -EINVAL;
} else {
++(*arg_index);
}
return 0;
}
Expand Down Expand Up @@ -168,7 +171,7 @@ int execute_add(const po::variables_map &vm,
}

std::string lock_cookie;
r = get_id(vm, &lock_cookie);
r = get_id(vm, &arg_index, &lock_cookie);
if (r < 0) {
return r;
}
Expand Down Expand Up @@ -227,12 +230,12 @@ int execute_remove(const po::variables_map &vm,
}

std::string lock_cookie;
r = get_id(vm, &lock_cookie);
r = get_id(vm, &arg_index, &lock_cookie);
if (r < 0) {
return r;
}

std::string lock_client = utils::get_positional_argument(vm, 2);
std::string lock_client = utils::get_positional_argument(vm, arg_index);
if (lock_client.empty()) {
std::cerr << "rbd: locker was not specified" << std::endl;
return -EINVAL;
Expand Down