added main routine

This commit is contained in:
Tobias Schmidl 2022-10-06 11:18:53 +02:00
parent 1e534a6c67
commit ee5afc2387
2 changed files with 70 additions and 0 deletions

View file

@ -81,3 +81,11 @@ target_link_libraries(
)
add_test(NAME test1 COMMAND $[PROJECT_NAME}_test)
add_executable(${PROJECT_NAME} main.cpp)
target_link_libraries(
${PROJECT_NAME}
PRIVATE Boost::filesystem
Boost::system
Boost::program_options
dir_monitor
)

62
main.cpp Normal file
View file

@ -0,0 +1,62 @@
/**
* @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;
}