Commit 75cd26c3 authored by Michael Ott's avatar Michael Ott
Browse files

Add proper command line parsing

parent 4ea9e9b7
...@@ -32,15 +32,46 @@ typedef struct { ...@@ -32,15 +32,46 @@ typedef struct {
std::string publicName; std::string publicName;
} sensor_t; } sensor_t;
void usage(int argc, char* argv[])
{
std::cout << "Usage: " << argv[0] << " [-h <host>] <CSV File> <SensorPrefix>" << std::endl << std::endl;
std::cout << " -h <host> - Database hostname" << std::endl;
std::cout << " CSV File - CSV file with sensor readings. First row has to contain sensor names" << std::endl;
std::cout << " SensorPrefix - Prefix to use for sensor names" << std::endl;
}
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
/* Check command line parameters */
if (argc < 3) {
usage(argc, argv);
exit(EXIT_FAILURE);
}
int ret;
const char *host = getenv("DCDB_HOSTNAME");
if (!host) {
host = "localhost";
}
while ((ret=getopt(argc, argv, "+h:"))!=-1) {
switch(ret) {
case 'h':
host = optarg;
break;
default:
usage(argc, argv);
exit(EXIT_FAILURE);
}
}
/* Connect to the data store */ /* Connect to the data store */
std::cout << std::endl; std::cout << std::endl;
std::cout << "Connecting to the data store..." << std::endl; std::cout << "Connecting to the data store..." << std::endl;
DCDB::Connection* connection; DCDB::Connection* connection;
connection = new DCDB::Connection(); connection = new DCDB::Connection();
connection->setHostname("127.0.0.1"); connection->setHostname(host);
if (!connection->connect()) { if (!connection->connect()) {
std::cout << "Cannot connect to database." << std::endl; std::cout << "Cannot connect to database." << std::endl;
return 1; return 1;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment