]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
Merge branch 'wip-argparse'
authorColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Tue, 6 Sep 2011 22:39:30 +0000 (15:39 -0700)
committerColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Tue, 6 Sep 2011 22:39:30 +0000 (15:39 -0700)
Conflicts:
src/rgw/rgw_admin.cc

1  2 
src/cosd.cc
src/rados.cc
src/rgw/rgw_admin.cc

diff --cc src/cosd.cc
Simple merge
diff --cc src/rados.cc
Simple merge
index a5aca96c795a0b16bc306f8456a3fd793d80f6ff,7ed07881956009c12a3cc932e19019f16c1a7a58..dd6d31f9f850a3b2684dd2fd7202c25266308549
@@@ -533,20 -483,10 +532,10 @@@ int main(int argc, char **argv
    global_init(args, CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_UTILITY, 0);
    common_init_finish(g_ceph_context);
  
-   const char *user_id = 0;
-   const char *access_key = 0;
-   const char *secret_key = 0;
-   const char *user_email = 0;
-   const char *display_name = 0;
-   const char *bucket_name = 0;
+   std::string user_id, access_key, secret_key, user_email, display_name;
 -  std::string bucket_name, object, openstack_user, openstack_key;
++  std::string bucket_name, object, swift_user, swift_key;
+   std::string date, time, subuser, access, format;
    rgw_bucket bucket;
-   const char *object = 0;
-   const char *swift_user = 0;
-   const char *swift_key = 0;
-   const char *date = 0;
-   const char *time = 0;
-   const char *subuser = 0;
-   const char *access = 0;
    uint32_t perm_mask = 0;
    uint64_t auid = -1;
    RGWUserInfo info;
    RGWPoolInfo pool_info;
    bool pretty_format = false;
  
-   FOR_EACH_ARG(args) {
-     if (CEPH_ARGPARSE_EQ("help", 'h')) {
+   std::string val;
+   std::ostringstream errs;
+   long long tmp = 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();
        return 0;
-     } else if (CEPH_ARGPARSE_EQ("uid", 'i')) {
-       CEPH_ARGPARSE_SET_ARG_VAL(&user_id, OPT_STR);
-     } else if (CEPH_ARGPARSE_EQ("access-key", '\0')) {
-       CEPH_ARGPARSE_SET_ARG_VAL(&access_key, OPT_STR);
-     } else if (CEPH_ARGPARSE_EQ("subuser", '\0')) {
-       CEPH_ARGPARSE_SET_ARG_VAL(&subuser, OPT_STR);
-     } else if (CEPH_ARGPARSE_EQ("secret", 's')) {
-       CEPH_ARGPARSE_SET_ARG_VAL(&secret_key, OPT_STR);
-     } else if (CEPH_ARGPARSE_EQ("email", 'e')) {
-       CEPH_ARGPARSE_SET_ARG_VAL(&user_email, OPT_STR);
-     } else if (CEPH_ARGPARSE_EQ("display-name", 'n')) {
-       CEPH_ARGPARSE_SET_ARG_VAL(&display_name, OPT_STR);
-     } else if (CEPH_ARGPARSE_EQ("bucket", 'b')) {
-       CEPH_ARGPARSE_SET_ARG_VAL(&bucket_name, OPT_STR);
-     } else if (CEPH_ARGPARSE_EQ("object", 'o')) {
-       CEPH_ARGPARSE_SET_ARG_VAL(&object, OPT_STR);
-     } else if (CEPH_ARGPARSE_EQ("gen-access-key", '\0')) {
-       CEPH_ARGPARSE_SET_ARG_VAL(&gen_key, OPT_BOOL);
-     } else if (CEPH_ARGPARSE_EQ("gen-secret", '\0')) {
-       CEPH_ARGPARSE_SET_ARG_VAL(&gen_secret, OPT_BOOL);
-     } else if (CEPH_ARGPARSE_EQ("auth-uid", 'a')) {
-       CEPH_ARGPARSE_SET_ARG_VAL(&auid, OPT_LONGLONG);
-     } else if (CEPH_ARGPARSE_EQ("swift-user", '\0')) {
-       CEPH_ARGPARSE_SET_ARG_VAL(&swift_user, OPT_STR);
-     } else if (CEPH_ARGPARSE_EQ("swift-secret", '\0')) {
-       CEPH_ARGPARSE_SET_ARG_VAL(&swift_key, OPT_STR);
-     } else if (CEPH_ARGPARSE_EQ("date", '\0')) {
-       CEPH_ARGPARSE_SET_ARG_VAL(&date, OPT_STR);
-     } else if (CEPH_ARGPARSE_EQ("time", '\0')) {
-       CEPH_ARGPARSE_SET_ARG_VAL(&time, OPT_STR);
-     } else if (CEPH_ARGPARSE_EQ("access", '\0')) {
-       CEPH_ARGPARSE_SET_ARG_VAL(&access, OPT_STR);
-       perm_mask = str_to_perm(access);
-     } else if (CEPH_ARGPARSE_EQ("bucket-id", '\0')) {
-       CEPH_ARGPARSE_SET_ARG_VAL(&bucket_id, OPT_LONGLONG);
+     } else if (ceph_argparse_witharg(args, i, &val, "-i", "--uid", (char*)NULL)) {
+       user_id = val;
+     } else if (ceph_argparse_witharg(args, i, &val, "--access-key", (char*)NULL)) {
+       access_key = val;
+     } else if (ceph_argparse_witharg(args, i, &val, "--subuser", (char*)NULL)) {
+       subuser = val;
+     } else if (ceph_argparse_witharg(args, i, &val, "--secret", (char*)NULL)) {
+       secret_key = val;
+     } else if (ceph_argparse_witharg(args, i, &val, "-e", "--email", (char*)NULL)) {
+       user_email = val;
+     } else if (ceph_argparse_witharg(args, i, &val, "-n", "--display-name", (char*)NULL)) {
+       display_name = val;
+     } else if (ceph_argparse_witharg(args, i, &val, "-b", "--bucket", (char*)NULL)) {
+       bucket_name = val;
+     } else if (ceph_argparse_witharg(args, i, &val, "-o", "--object", (char*)NULL)) {
+       object = val;
+     } else if (ceph_argparse_flag(args, i, "--gen-access-key", (char*)NULL)) {
+       gen_key = true;
+     } else if (ceph_argparse_flag(args, i, "--gen-secret", (char*)NULL)) {
+       gen_secret = true;
+     } else if (ceph_argparse_withlonglong(args, i, &tmp, &errs, "-a", "--auth-uid", (char*)NULL)) {
+       if (!errs.str().empty()) {
+       cerr << errs.str() << std::endl;
+       exit(EXIT_FAILURE);
+       }
+       auid = tmp;
+     } else if (ceph_argparse_witharg(args, i, &val, "--os-user", (char*)NULL)) {
 -      openstack_user = val;
++      swift_user = val;
+     } else if (ceph_argparse_witharg(args, i, &val, "--os-secret", (char*)NULL)) {
 -      openstack_key = val;
++      swift_key = val;
+     } else if (ceph_argparse_witharg(args, i, &val, "--date", (char*)NULL)) {
+       date = val;
+     } else if (ceph_argparse_witharg(args, i, &val, "--time", (char*)NULL)) {
+       time = val;
+     } else if (ceph_argparse_witharg(args, i, &val, "--access", (char*)NULL)) {
+       access = val;
+       perm_mask = str_to_perm(access.c_str());
+     } else if (ceph_argparse_withlonglong(args, i, &tmp, &errs, "--bucket-id", (char*)NULL)) {
+       if (!errs.str().empty()) {
+       cerr << errs.str() << std::endl;
+       exit(EXIT_FAILURE);
+       }
+       bucket_id = tmp;
        if (bucket_id < 0) {
          cerr << "bad bucket-id: " << bucket_id << std::endl;
          return usage();
        cerr << "could not find user by specified access key" << std::endl;
        }
      }
-     if (!found && swift_user) {
 -    if (!found && (!openstack_user.empty())) {
 -      s = openstack_user;
 -      if (rgw_get_user_info_by_openstack(s, info) >= 0) {
++    if (!found && (!swift_user.empty())) {
 +      s = swift_user;
 +      if (rgw_get_user_info_by_swift(s, info) >= 0) {
        found = true;
        } else
 -        cerr << "could not find user by specified openstack username" << std::endl;
 +        cerr << "could not find user by specified swift username" << std::endl;
      }
      if (found)
        user_id = info.user_id.c_str();
        info.user_email = user_email;
      if (auid != (uint64_t)-1)
        info.auid = auid;
-     if (swift_user)
 -    if (!openstack_user.empty())
 -      info.openstack_name = openstack_user;
 -    if (!openstack_key.empty())
 -      info.openstack_key = openstack_key;
++    if (!swift_user.empty())
 +      info.swift_name = swift_user;
-     if (swift_key)
++    if (!swift_key.empty())
 +      info.swift_key = swift_key;
-     if (subuser) {
+     if (!subuser.empty()) {
        RGWSubUser u;
        u.name = subuser;
        u.perm_mask = perm_mask;
  
      remove_old_indexes(old_info, info);
  
-     show_user_info(info, format, formatter);
 -    show_user_info(info);
++    show_user_info(info, format.c_str(), formatter);
      break;
  
    case OPT_SUBUSER_RM:
        cerr << "error storing user info: " << cpp_strerror(-err) << std::endl;
        break;
      }
-     show_user_info(info, format, formatter);
 -    show_user_info(info);
++    show_user_info(info, format.c_str(), formatter);
      break;
  
    case OPT_KEY_RM:
          break;
        }
      }
-     show_user_info(info, format, formatter);
 -    show_user_info(info);
++    show_user_info(info, format.c_str(), formatter);
      break;
  
    case OPT_USER_INFO:
-     show_user_info(info, format, formatter);
 -    show_user_info(info);
++    show_user_info(info, format.c_str(), formatter);
      break;
    }