]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/common/ceph_argparse.cc
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / common / ceph_argparse.cc
index a89de95f6e405fb2988e8dc8918128efaa02e184..818f8d0767514cda62744fe1091a43ec33be8b0f 100644 (file)
@@ -11,6 +11,7 @@
  * Foundation.  See file COPYING.
  *
  */
+#include <stdarg.h>
 
 #include "auth/Auth.h"
 #include "common/ceph_argparse.h"
@@ -200,21 +201,40 @@ void ceph_arg_value_type(const char * nextargstr, bool *bool_option, bool *bool_
   return;
 }
 
-bool parse_ip_port_vec(const char *s, vector<entity_addr_t>& vec)
+
+bool parse_ip_port_vec(const char *s, vector<entity_addrvec_t>& vec, int type)
 {
-  const char *p = s;
-  const char *end = p + strlen(p);
-  while (p < end) {
-    entity_addr_t a;
-    //cout << " parse at '" << p << "'" << std::endl;
-    if (!a.parse(p, &p)) {
-      //dout(0) << " failed to parse address '" << p << "'" << dendl;
-      return false;
+  // first split by [ ;], which are not valid for an addrvec
+  list<string> items;
+  get_str_list(s, " ;", items);
+
+  for (auto& i : items) {
+    const char *s = i.c_str();
+    while (*s) {
+      const char *end;
+
+      // try parsing as an addr
+      entity_addr_t a;
+      if (a.parse(s, &end, type)) {
+       vec.push_back(entity_addrvec_t(a));
+       s = end;
+       if (*s == ',') {
+         ++s;
+       }
+       continue;
+      }
+
+      // ok, try parsing as an addrvec
+      entity_addrvec_t av;
+      if (!av.parse(s, &end)) {
+       return false;
+      }
+      vec.push_back(av);
+      s = end;
+      if (*s == ',') {
+       ++s;
+      }
     }
-    //cout << " got " << a << ", rest is '" << p << "'" << std::endl;
-    vec.push_back(a);
-    while (*p == ',' || *p == ' ' || *p == ';')
-      p++;
   }
   return true;
 }
@@ -544,13 +564,26 @@ static void generic_usage(bool is_server)
   cout.flush();
 }
 
+bool ceph_argparse_need_usage(const std::vector<const char*>& args)
+{
+  if (args.empty()) {
+    return true;
+  }
+  for (auto a : args) {
+    if (strcmp(a, "-h") == 0 ||
+       strcmp(a, "--help") == 0) {
+      return true;
+    }
+  }
+  return false;
+}
+
 void generic_server_usage()
 {
   generic_usage(true);
-  exit(1);
 }
+
 void generic_client_usage()
 {
   generic_usage(false);
-  exit(1);
 }