diff --git a/CMakeLists.txt b/CMakeLists.txt index d8aefb8..407fc0a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 +) diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..6ab7138 --- /dev/null +++ b/main.cpp @@ -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 +#include +#include + +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()->required(), "Input Directory")( + "output_file,o", value()->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(); + 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::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; +}