You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by be...@apache.org on 2012/04/25 20:10:01 UTC

svn commit: r1330454 - /incubator/mesos/trunk/src/log/main.cpp

Author: benh
Date: Wed Apr 25 18:10:01 2012
New Revision: 1330454

URL: http://svn.apache.org/viewvc?rev=1330454&view=rev
Log:
Cleaned up log utility.

Modified:
    incubator/mesos/trunk/src/log/main.cpp

Modified: incubator/mesos/trunk/src/log/main.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/log/main.cpp?rev=1330454&r1=1330453&r2=1330454&view=diff
==============================================================================
--- incubator/mesos/trunk/src/log/main.cpp (original)
+++ incubator/mesos/trunk/src/log/main.cpp Wed Apr 25 18:10:01 2012
@@ -20,12 +20,14 @@
 #include <list>
 #include <string>
 
-#include <process/dispatch.hpp>
 #include <process/process.hpp>
 
-#include "common/fatal.hpp"
 #include "common/foreach.hpp"
-#include "common/result.hpp"
+#include "common/logging.hpp"
+#include "common/utils.hpp"
+
+#include "configurator/configurator.hpp"
+#include "configurator/configuration.hpp"
 
 #include "log/replica.hpp"
 
@@ -33,40 +35,76 @@ using namespace mesos;
 using namespace mesos::internal;
 using namespace mesos::internal::log;
 
+using std::cerr;
+using std::cout;
+using std::endl;
+using std::string;
+
+
+void usage(const char* argv0, const Configurator& configurator)
+{
+  cerr << "Usage: " << utils::os::basename(argv0) << " [...] path/to/log"
+       << endl
+       << endl
+       << "Supported options:" << endl
+       << configurator.getUsage();
+}
+
 
 int main(int argc, char** argv)
 {
-  if (argc < 2) {
-    fatal("Usage: %s file <from> <to>", argv[0]);
+  Configurator configurator;
+  Logging::registerOptions(&configurator);
+
+  configurator.addOption<uint64_t>(
+      "from",
+      "Position from which to start reading in the log");
+
+  configurator.addOption<uint64_t>(
+      "to",
+      "Position from which to stop reading in the log");
+
+  configurator.addOption<bool>(
+      "help",
+      'h',
+      "Prints this usage message");
+
+  Configuration conf;
+  try {
+    conf = configurator.load(argc, argv);
+  } catch (const ConfigurationException& e) {
+    cerr << "Configuration error: " << e.what() << endl;
+    usage(argv[0], configurator);
+    exit(1);
   }
 
-  std::string file = argv[1];
+  if (argc < 2 || conf.contains("help")) {
+    usage(argv[0], configurator);
+    exit(1);
+  }
 
-  process::initialize(true);
+  Logging::init(argv[0], conf);
 
-  Replica replica(file);
+  string path = argv[argc - 1];
 
-  uint64_t from, to;
+  process::initialize(false);
 
-  if (argc != 4) {
-    process::Future<uint64_t> begin = replica.beginning();
-    process::Future<uint64_t> end = replica.ending();
+  Replica replica(path);
 
-    begin.await();
-    end.await();
+  process::Future<uint64_t> begin = replica.beginning();
+  process::Future<uint64_t> end = replica.ending();
 
-    CHECK(begin.isReady());
-    CHECK(end.isReady());
+  begin.await();
+  end.await();
 
-    from = begin.get();
-    to = end.get();
-  } else {
-    from = atoi(argv[2]);
-    to = atoi(argv[3]);
-  }
+  CHECK(begin.isReady());
+  CHECK(end.isReady());
+
+  uint64_t from = conf.get<uint64_t>("from", begin.get());
+  uint64_t to = conf.get<uint64_t>("to", end.get());
 
-  std::cout << std::endl << "Attempting to read the log from "
-            << from << " to " << to << std::endl << std::endl;
+  cerr << endl << "Attempting to read the log from "
+       << from << " to " << to << endl << endl;
 
   process::Future<std::list<Action> > actions = replica.read(from, to);
 
@@ -77,7 +115,7 @@ int main(int argc, char** argv)
   CHECK(actions.isReady());
 
   foreach (const Action& action, actions.get()) {
-    std::cout << "----------------------------------------------" << std::endl;
+    cout << "----------------------------------------------" << endl;
     action.PrintDebugString();
   }