Skip to content

Commit

Permalink
rbd.cc: use new argument parsing stuff
Browse files Browse the repository at this point in the history
Signed-off-by: Colin McCabe <[email protected]>
  • Loading branch information
cmccabe committed Sep 6, 2011
1 parent 316dd91 commit d481797
Showing 1 changed file with 44 additions and 32 deletions.
76 changes: 44 additions & 32 deletions src/rbd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,6 @@ int main(int argc, const char **argv)
librbd::Image image;

vector<const char*> args;
DEFINE_CONF_VARS(usage_exit);

argv_to_vec(argc, argv, args);
env_to_vec(args);
Expand All @@ -837,42 +836,55 @@ int main(int argc, const char **argv)
int order = 0;
const char *imgname = NULL, *snapname = NULL, *destname = NULL, *dest_poolname = NULL, *path = NULL, *secretfile = NULL, *user = NULL, *devpath = NULL;
bool is_snap_cmd = false;
FOR_EACH_ARG(args) {
if (CEPH_ARGPARSE_EQ("help", 'h')) {

std::string val;
std::ostringstream err;
long long sizell = 0;
for (std::vector<const char*>::iterator i = args.begin(); i != args.end(); ) {
if (ceph_argparse_double_dash(args, i)) {
break;
} else if (ceph_argparse_flag(args, i, "-h", "--help", (char*)NULL)) {
usage();
exit(0);
} else if (CEPH_ARGPARSE_EQ("pool", 'p')) {
CEPH_ARGPARSE_SET_ARG_VAL(&poolname, OPT_STR);
} else if (CEPH_ARGPARSE_EQ("dest-pool", '\0')) {
CEPH_ARGPARSE_SET_ARG_VAL(&dest_poolname, OPT_STR);
} else if (CEPH_ARGPARSE_EQ("snap", '\0')) {
CEPH_ARGPARSE_SET_ARG_VAL(&snapname, OPT_STR);
} else if (CEPH_ARGPARSE_EQ("image", 'i')) {
CEPH_ARGPARSE_SET_ARG_VAL(&imgname, OPT_STR);
} else if (CEPH_ARGPARSE_EQ("size", 's')) {
CEPH_ARGPARSE_SET_ARG_VAL(&size, OPT_LONGLONG);
size <<= 20; // MB -> bytes
} else if (CEPH_ARGPARSE_EQ("order", '\0')) {
CEPH_ARGPARSE_SET_ARG_VAL(&order, OPT_INT);
} else if (CEPH_ARGPARSE_EQ("path", '\0')) {
CEPH_ARGPARSE_SET_ARG_VAL(&path, OPT_STR);
} else if (CEPH_ARGPARSE_EQ("dest", '\0')) {
CEPH_ARGPARSE_SET_ARG_VAL(&destname, OPT_STR);
} else if (CEPH_ARGPARSE_EQ("secret", '\0')) {
CEPH_ARGPARSE_SET_ARG_VAL(&secretfile, OPT_STR);
} else if (CEPH_ARGPARSE_EQ("user", '\0')) {
CEPH_ARGPARSE_SET_ARG_VAL(&user, OPT_STR);
} else if (ceph_argparse_witharg(args, i, &val, "-p", "--pool", (char*)NULL)) {
poolname = strdup(val.c_str());
} else if (ceph_argparse_witharg(args, i, &val, "--dest-pool", (char*)NULL)) {
dest_poolname = strdup(val.c_str());
} else if (ceph_argparse_witharg(args, i, &val, "--snap", (char*)NULL)) {
snapname = strdup(val.c_str());
} else if (ceph_argparse_witharg(args, i, &val, "-i", "--image", (char*)NULL)) {
imgname = strdup(val.c_str());
} else if (ceph_argparse_withlonglong(args, i, &sizell, &err, "-s", "--size", (char*)NULL)) {
if (!err.str().empty()) {
cerr << err.str() << std::endl;
exit(EXIT_FAILURE);
}
size = sizell;
} else if (ceph_argparse_withint(args, i, &order, &err, "--order", (char*)NULL)) {
if (!err.str().empty()) {
cerr << err.str() << std::endl;
exit(EXIT_FAILURE);
}
} else if (ceph_argparse_witharg(args, i, &val, "--path", (char*)NULL)) {
path = strdup(val.c_str());
} else if (ceph_argparse_witharg(args, i, &val, "--dest", (char*)NULL)) {
destname = strdup(val.c_str());
} else if (ceph_argparse_witharg(args, i, &val, "--secret", (char*)NULL)) {
secretfile = strdup(val.c_str());
} else if (ceph_argparse_witharg(args, i, &val, "--user", (char*)NULL)) {
user = strdup(val.c_str());
} else {
const char *v = *i;
if (!opt_cmd) {
opt_cmd = get_cmd(CEPH_ARGPARSE_VAL, &is_snap_cmd);
opt_cmd = get_cmd(v, &is_snap_cmd);
if (opt_cmd < 0) {
cerr << "invalid command: " << CEPH_ARGPARSE_VAL << std::endl;
cerr << "invalid command: " << v << std::endl;
usage_exit();
}
} else {
switch (opt_cmd) {
case OPT_LIST:
set_conf_param(CEPH_ARGPARSE_VAL, &poolname, NULL);
set_conf_param(v, &poolname, NULL);
break;
case OPT_INFO:
case OPT_CREATE:
Expand All @@ -884,20 +896,20 @@ int main(int argc, const char **argv)
case OPT_SNAP_LIST:
case OPT_WATCH:
case OPT_MAP:
set_conf_param(CEPH_ARGPARSE_VAL, &imgname, NULL);
set_conf_param(v, &imgname, NULL);
break;
case OPT_UNMAP:
set_conf_param(CEPH_ARGPARSE_VAL, &devpath, NULL);
set_conf_param(v, &devpath, NULL);
break;
case OPT_EXPORT:
set_conf_param(CEPH_ARGPARSE_VAL, &imgname, &path);
set_conf_param(v, &imgname, &path);
break;
case OPT_IMPORT:
set_conf_param(CEPH_ARGPARSE_VAL, &path, &destname);
set_conf_param(v, &path, &destname);
break;
case OPT_COPY:
case OPT_RENAME:
set_conf_param(CEPH_ARGPARSE_VAL, &imgname, &destname);
set_conf_param(v, &imgname, &destname);
break;
}
}
Expand Down

0 comments on commit d481797

Please sign in to comment.