Added argument parsing.

master
Sean McArdle 2017-06-22 11:53:03 -07:00
parent aa777b54d8
commit 2c782d47dd
1 changed files with 39 additions and 3 deletions

View File

@ -7,10 +7,14 @@
#include <iostream>
#include <chrono>
#include <thread>
#include <vector>
#include <string>
#include "efsw/efsw.hpp"
#include "parg.h"
const char * VERSION_STRING = "0.0.1";
class UpdateListener : public efsw::FileWatchListener
{
public:
@ -39,16 +43,48 @@ public:
};
int main() {
std::cout << "Hello, World!" << '\n';
int
main(int argc, char *argv[]) {
using namespace std;
struct parg_state ps;
parg_init(&ps);
int c = 0;
vector<string> watch_inode;
while (-1 != (c = parg_getopt(&ps, argc, argv, "f:d:v"))) {
switch (c) {
case 1:
printf("nonoption '%s'\n", ps.optarg);
break;
case 'f':
case 'd':
if (NULL == ps.optarg) break;
watch_inode.push_back(std::string(ps.optarg));
break;
case 'v':
printf("Version: %s", VERSION_STRING);
return 0;
break;
default:
break;
}
}
auto fwatcher = new efsw::FileWatcher();
auto listener = new UpdateListener();
vector<efsw::WatchID> watchers;
watchers.resize(watch_inode.size() * 2);
// Add a folder to watch, and get the efsw::WatchID
// It will watch the /tmp folder recursively ( the third parameter indicates that is recursive )
// Reporting the files and directories changes to the instance of the listener
efsw::WatchID watchID = fwatcher->addWatch( "~/Logs", listener, true );
for (auto f : watch_inode) {
printf("Watch: %s\n", f.c_str());
watchers.push_back(fwatcher->addWatch(f, listener, true));
}
// Start watching asynchronously the directories
fwatcher->watch();