]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
monmaptool: don't spew usage on any error
authorSage Weil <sage@redhat.com>
Mon, 11 Feb 2019 15:05:42 +0000 (09:05 -0600)
committerSage Weil <sage@redhat.com>
Tue, 12 Feb 2019 18:40:36 +0000 (12:40 -0600)
Signed-off-by: Sage Weil <sage@redhat.com>
src/test/cli/monmaptool/add-exists.t
src/test/cli/monmaptool/feature-set-unset-list.t
src/test/cli/monmaptool/help.t
src/test/cli/monmaptool/rm-nonexistent.t
src/tools/monmaptool.cc

index 182d012bf2cdadd1ad989822aa7d986c9d9d0494..d652a1bdd0512dab7d0ebaef0b0fc427d9ae7c6f 100644 (file)
   $ monmaptool --add foo 3.4.5.6:7890 mymonmap
   monmaptool: monmap file mymonmap
   monmaptool: map already contains mon.foo
-   usage: [--print] [--create [--clobber][--fsid uuid]]
-          [--enable-all-features]
-          [--generate] [--set-initial-members]
-          [--add name 1.2.3.4:567] [--rm name]
-          [--feature-list [plain|parseable]]
-          [--feature-set <value> [--optional|--persistent]]
-          [--feature-unset <value> [--optional|--persistent]] <mapfilename>
+  monmaptool -h for usage
   [1]
 
   $ monmaptool --print mymonmap
index 4f22d26f518ad0fe16908bd118bbb008a052dbd4..c44f14bcff56cc145281c2c463072c5a7f67446d 100644 (file)
 
   $ monmaptool --feature-set foo /tmp/test.monmap.1234
   unknown features name 'foo' or unable to parse value: Expected option value to be integer, got 'foo'
-   usage: [--print] [--create [--clobber][--fsid uuid]]
-          [--enable-all-features]
-          [--generate] [--set-initial-members]
-          [--add name 1.2.3.4:567] [--rm name]
-          [--feature-list [plain|parseable]]
-          [--feature-set <value> [--optional|--persistent]]
-          [--feature-unset <value> [--optional|--persistent]] <mapfilename>
+  monmaptool -h for usage
   [1]
 
   $ monmaptool --feature-set kraken --feature-set 64 --optional --feature-set 32 --persistent /tmp/test.monmap.1234
index 5c5a95cc25768cfe91d3e12954ad99b813f3d0b9..c976aa0753eb157e62b3db2147c3939586fa0434 100644 (file)
@@ -1,5 +1,5 @@
   $ monmaptool --help
-   usage: [--print] [--create [--clobber][--fsid uuid]]
+  usage: monmaptool [--print] [--create [--clobber] [--fsid uuid]]
           [--enable-all-features]
           [--generate] [--set-initial-members]
           [--add name 1.2.3.4:567] [--rm name]
index b3d7fbcf5aadc023354f761c33dfcb72663f584c..ef680d85c5ecc7c484a7ddf47d6f7dec59bea55c 100644 (file)
@@ -9,13 +9,7 @@
   monmaptool: monmap file mymonmap
   monmaptool: removing doesnotexist
   monmaptool: map does not contain doesnotexist
-   usage: [--print] [--create [--clobber][--fsid uuid]]
-          [--enable-all-features]
-          [--generate] [--set-initial-members]
-          [--add name 1.2.3.4:567] [--rm name]
-          [--feature-list [plain|parseable]]
-          [--feature-set <value> [--optional|--persistent]]
-          [--feature-unset <value> [--optional|--persistent]] <mapfilename>
+  monmaptool -h for usage
   [1]
 
   $ monmaptool --print mymonmap
index 9ce4a3221a9b0b0b491d239a65760577a2dab4d2..25b4d64590d9d2bc0a566fd34048ae679bab7205 100644 (file)
@@ -23,7 +23,7 @@
 
 void usage()
 {
-  cout << " usage: [--print] [--create [--clobber][--fsid uuid]]\n"
+  cout << "usage: monmaptool [--print] [--create [--clobber] [--fsid uuid]]\n"
        << "        [--enable-all-features]\n"
        << "        [--generate] [--set-initial-members]\n"
        << "        [--add name 1.2.3.4:567] [--rm name]\n"
@@ -32,6 +32,11 @@ void usage()
        << "        [--feature-unset <value> [--optional|--persistent]] "
        << "<mapfilename>"
        << std::endl;
+}
+
+void helpful_exit()
+{
+  cerr << "monmaptool -h for usage" << std::endl;
   exit(1);
 }
 
@@ -217,7 +222,7 @@ int main(int argc, const char **argv)
       string name = *i;
       i = args.erase(i);
       if (i == args.end())
-       usage();
+       helpful_exit();
       entity_addr_t addr;
       if (!addr.parse(*i)) {
        cerr << me << ": invalid ip:port '" << *i << "'" << std::endl;
@@ -230,7 +235,7 @@ int main(int argc, const char **argv)
       string name = *i;
       i = args.erase(i);
       if (i == args.end())
-       usage();
+       helpful_exit();
       entity_addrvec_t addrs;
       if (!addrs.parse(*i)) {
        cerr << me << ": invalid ip:port '" << *i << "'" << std::endl;
@@ -257,7 +262,7 @@ int main(int argc, const char **argv)
         f.type = feature_op_t::type_t::PARSEABLE;
       } else if (format != "plain") {
         cerr << "invalid format type for list: '" << val << "'" << std::endl;
-        usage();
+        helpful_exit();
       }
 
       features.push_back(f);
@@ -267,7 +272,7 @@ int main(int argc, const char **argv)
       // parse value
       feature_op_t f(feature_op_t::op_t::OP_SET);
       if (!f.parse_value(val, &cerr)) {
-        usage();
+        helpful_exit();
       }
       features.push_back(f);
 
@@ -276,17 +281,17 @@ int main(int argc, const char **argv)
       // parse value
       feature_op_t f(feature_op_t::op_t::OP_UNSET);
       if (!f.parse_value(val, &cerr)) {
-        usage();
+        helpful_exit();
       }
       features.push_back(f);
     } else if (ceph_argparse_flag(args, i, "--optional", (char*)NULL)) {
       if (features.empty()) {
-        usage();
+        helpful_exit();
       }
       features.back().set_optional();
     } else if (ceph_argparse_flag(args, i, "--persistent", (char*)NULL)) {
       if (features.empty()) {
-        usage();
+        helpful_exit();
       }
       features.back().set_persistent();
     } else {
@@ -295,11 +300,11 @@ int main(int argc, const char **argv)
   }
   if (args.empty()) {
     cerr << me << ": must specify monmap filename" << std::endl;
-    usage();
+    helpful_exit();
   }
   else if (args.size() > 1) {
     cerr << me << ": too many arguments" << std::endl;
-    usage();
+    helpful_exit();
   }
   fn = args[0];
   
@@ -375,7 +380,7 @@ int main(int argc, const char **argv)
     entity_addrvec_t addrs;
     if (monmap.contains(p.first)) {
       cerr << me << ": map already contains mon." << p.first << std::endl;
-      usage();
+      helpful_exit();
     }
     if (addr.get_port() == 0) {
       if (monmap.persistent_features.contains_all(
@@ -403,18 +408,18 @@ int main(int argc, const char **argv)
     }
     if (monmap.contains(addrs)) {
       cerr << me << ": map already contains " << addrs << std::endl;
-      usage();
+      helpful_exit();
     }
     monmap.add(p.first, addrs);
   }
   for (auto& p : addv) {
     if (monmap.contains(p.first)) {
       cerr << me << ": map already contains mon." << p.first << std::endl;
-      usage();
+      helpful_exit();
     }
     if (monmap.contains(p.second)) {
       cerr << me << ": map already contains " << p.second << std::endl;
-      usage();
+      helpful_exit();
     }
     monmap.add(p.first, p.second);
   }
@@ -422,7 +427,7 @@ int main(int argc, const char **argv)
     cout << me << ": removing " << p << std::endl;
     if (!monmap.contains(p)) {
       cerr << me << ": map does not contain " << p << std::endl;
-      usage();
+      helpful_exit();
     }
     monmap.remove(p);
   }
@@ -431,8 +436,10 @@ int main(int argc, const char **argv)
     modified = true;
   }
 
-  if (!print && !modified && !show_features)
-    usage();
+  if (!print && !modified && !show_features) {
+    cerr << "no action specified" << std::endl;
+    helpful_exit();
+  }
 
   if (print) 
     monmap.print(cout);