ADD_EXECUTABLE(${SERVER_CODENAME} ${project_SRCS} )
## Link libraries ##############################################################
+FIND_PACKAGE (Boost COMPONENTS program_options REQUIRED)
+MESSAGE ("Include dirs of boost: " ${Boost_INCLUDE_DIRS} )
+MESSAGE ("Libs of boost: " ${Boost_LIBRARIES} )
+
PKG_CHECK_MODULES(SERVER_DEPS REQUIRED libvirt json)
-INCLUDE_DIRECTORIES(SYSTEM ${SERVER_DEPS_INCLUDE_DIRS})
-TARGET_LINK_LIBRARIES(${SERVER_CODENAME} ${SERVER_DEPS_LIBRARIES})
+INCLUDE_DIRECTORIES(SYSTEM ${SERVER_DEPS_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS})
+TARGET_LINK_LIBRARIES(${SERVER_CODENAME} ${SERVER_DEPS_LIBRARIES} ${Boost_LIBRARIES})
## Install #####################################################################
INSTALL(TARGETS ${SERVER_CODENAME} DESTINATION bin)
\ No newline at end of file
* @brief Main file for the Security Containers Daemon
*/
+#include <boost/program_options.hpp>
#include <iostream>
-#include <getopt.h> // For getopt
+
+namespace po = boost::program_options;
+
+namespace {
+ const std::string PROGRAM_NAME_AND_VERSION =
+ "Security Containers Server " PROGRAM_VERSION;
+}
int main(int argc, char* argv[])
{
- int optIndex = 0;
-
- const option longOptions[] = {
- {"help", no_argument, 0, 'h'},
- {"version", no_argument, 0, 'v'},
- {0, 0, 0, 0}
- };
-
- for (;;) {
- int opt = getopt_long(argc, argv,
- "hv", // ':' after arg is the parameter
- longOptions,
- &optIndex);
- if (opt == -1) {
- break;
- }
+ po::options_description desc("Allowed options");
- // If option comes with a parameter,
- // the param is stored in optarg global variable by getopt_long.
- switch (opt) {
- case 0:
- // A flag was set
- break;
-
- case '?':
- // No such command.
- // getopt_long already printed an error message to stderr.
- return 1;
-
- case 'v':
- std::cout << "Security Containers Server v. 0.1.0" << std::endl;
- return 0;
-
- case 'h':
- std::cout << "Security Containers Server v. 0.1.0 \n"
- << " Options: \n"
- << " -h,--help print this help \n"
- << " -v,--version show applcation version"
- << std::endl;
- return 0;
-
- default:
- break;
- }
- }
+ desc.add_options()
+ ("help,h", "print this help")
+ ("version,v", "show application version")
+ ;
+
+ po::variables_map vm;
+ po::basic_parsed_options< char > parsed =
+ po::command_line_parser(argc, argv).options(desc).allow_unregistered().run();
+
+ std::vector<std::string> unrecognized_options =
+ po::collect_unrecognized(parsed.options, po::include_positional);
- // Print unknown remaining command line arguments
- if (optind < argc) {
- std::cerr << "Unknown options: ";
- while (optind < argc) {
- std::cerr << argv[optind++] << " ";
+ if (!unrecognized_options.empty()) {
+ std::cout << "Unrecognized options: ";
+
+ for (auto& uo: unrecognized_options) {
+ std::cout << ' ' << uo;
}
- std::cerr << std::endl;
+
+ std::cout << std::endl << std::endl;
+ std::cout << desc << std::endl;
+
return 1;
}
+
+ po::store(parsed, vm);
+ po::notify(vm);
+
+ if (vm.count("help")) {
+ std::cout << desc << std::endl;
+ return 0;
+ } else if (vm.count("version")) {
+ std::cout << PROGRAM_NAME_AND_VERSION << std::endl;
+ return 0;
+ }
+
+ return 0;
}