Index: tools/battor_agent/battor_agent_bin.cc |
diff --git a/tools/battor_agent/battor_agent_bin.cc b/tools/battor_agent/battor_agent_bin.cc |
index 360146dd39d81771ec4d0d8779fa84e99147d973..93036e2fcb9b37a4be51a8cca2b97d2aea950f76 100644 |
--- a/tools/battor_agent/battor_agent_bin.cc |
+++ b/tools/battor_agent/battor_agent_bin.cc |
@@ -19,6 +19,7 @@ |
#include "base/threading/thread.h" |
#include "tools/battor_agent/battor_agent.h" |
#include "tools/battor_agent/battor_error.h" |
+#include "tools/battor_agent/battor_finder.h" |
using std::cout; |
using std::endl; |
@@ -47,12 +48,11 @@ void PrintSupportsExplicitClockSync() { |
cout << battor::BattOrAgent::SupportsExplicitClockSync() << endl; |
} |
-// Retrieves argument argnum from the argument list, printing the usage |
-// guidelines and exiting with an error code if the argument doesn't exist. |
+// Retrieves argument argnum from the argument list, or an empty string if the |
+// argument doesn't exist. |
std::string GetArg(int argnum, int argc, char* argv[]) { |
if (argnum >= argc) { |
- PrintUsage(); |
- exit(1); |
+ return std::string(); |
} |
return argv[argnum]; |
@@ -89,6 +89,10 @@ class BattOrAgentBin : public BattOrAgent::Listener { |
// Runs the BattOr binary and returns the exit code. |
int Run(int argc, char* argv[]) { |
std::string cmd = GetArg(1, argc, argv); |
+ if (cmd.empty()) { |
+ PrintUsage(); |
+ exit(1); |
+ } |
// SupportsExplicitClockSync doesn't need to use the serial connection, so |
// handle it separately. |
@@ -98,6 +102,18 @@ class BattOrAgentBin : public BattOrAgent::Listener { |
} |
std::string path = GetArg(2, argc, argv); |
+ // If no path is specified, see if we can find a BattOr and use that. |
+ if (path.empty()) |
+ path = BattOrFinder::FindBattOr(); |
+ |
+ // If we don't have any BattOr to use, exit. |
+ if (path.empty()) { |
+ cout << "Unable to find a BattOr, and no explicit BattOr path was " |
+ "specified." |
+ << endl; |
+ exit(1); |
+ } |
+ |
SetUp(path); |
if (cmd == "StartTracing") { |