collector/main.cpp

63 lines
1.9 KiB
C++
Raw Permalink Normal View History

2022-10-06 11:18:53 +02:00
/**
* @file main.cpp
* The main executable
*
* @author Tobias Schmidl
* @copyright Copyright © 2022, Tobias Schmidl
* SPDX-License-Identifier: MIT
*/
#include "collector.hpp"
#include "monitor.hpp"
#include "version.hpp"
#include <boost/program_options.hpp>
#include <filesystem>
#include <iostream>
using namespace collector::monitor;
using namespace collector::collector;
using namespace boost::program_options;
int
main(int argc, const char* argv[])
{
std::cerr << argv[0] << " Version v" << VERSION << "\n";
options_description description{ "Options" };
description.add_options()("help,h", "Help screen")(
"input_dir,i", value<std::string>()->required(), "Input Directory")(
"output_file,o", value<std::string>()->required(), "Output Tarball");
variables_map vm;
try {
store(parse_command_line(argc, argv, description), vm);
notify(vm);
} catch (std::exception& err) {
std::cerr << "Error: " << err.what() << "\n";
std::cerr << description << std::endl;
return 1;
}
std::filesystem::path input_dir, output_file;
if (vm.count("help")) {
std::cerr << description << std::endl;
return 1;
}
if (vm.count("input_dir")) {
input_dir = vm["input_dir"].as<std::string>();
if (!std::filesystem::is_directory(input_dir)) {
std::cerr << input_dir << " is not a valid directory." << std::endl;
return 1;
} else
std::cerr << "input dir: " << input_dir << "\n";
}
if (vm.count("output_file")) {
output_file = vm["output_file"].as<std::string>();
std::cout << "output file: " << output_file << "\n";
}
boost::asio::io_service service;
Collector collector(service, input_dir, output_file);
return (collector() && std::filesystem::is_regular_file(output_file)) ? 0
: 2;
}