diff options
| author | thecharlesblake | 2017-10-16 14:15:25 +0100 |
|---|---|---|
| committer | thecharlesblake | 2017-10-26 14:51:33 +0100 |
| commit | 9101c98f951e7b104e6969fd5984379ca04745ea (patch) | |
| tree | 71a154d956da31c55c13402bb8b2f04c6aa36a01 | |
| parent | Move setup classes to legacy (diff) | |
| download | metasol-9101c98f951e7b104e6969fd5984379ca04745ea.tar.gz metasol-9101c98f951e7b104e6969fd5984379ca04745ea.zip | |
Add demo command line parsing
| -rw-r--r-- | CMakeLists.txt | 7 | ||||
| -rw-r--r-- | src/main/command_line_helper.cpp | 18 | ||||
| -rw-r--r-- | src/main/command_line_helper.h | 12 | ||||
| -rw-r--r-- | src/main/main.cpp | 29 |
4 files changed, 64 insertions, 2 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index b292ab7..9fa09c3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,7 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) ## source files ############################################################### ############################################################################### -set(sources src/main/main.cpp) +set(sources src/main/main.cpp src/main/command_line_helper.cpp src/main/command_line_helper.h) set(sources_test src/test/main_test.cpp) ############################################################################### @@ -20,7 +20,10 @@ set(sources_test src/test/main_test.cpp) set(Boost_USE_STATIC_LIBS OFF) set(Boost_USE_MULTITHREADED ON) set(Boost_USE_STATIC_RUNTIME OFF) -find_package(Boost 1.63.0 REQUIRED COMPONENTS log) + +set(boost_components log program_options) + +find_package(Boost 1.63.0 REQUIRED COMPONENTS ${boost_components}) if(Boost_FOUND) include_directories(${Boost_INCLUDE_DIRS}) diff --git a/src/main/command_line_helper.cpp b/src/main/command_line_helper.cpp new file mode 100644 index 0000000..38b9af0 --- /dev/null +++ b/src/main/command_line_helper.cpp @@ -0,0 +1,18 @@ +// +// Created by thecharlesblake on 10/16/17. +// + +#include "command_line_helper.h" +#include <boost/program_options.hpp> + +namespace po = boost::program_options; + +po::options_description get_options_desc() { + // Creates the command line options + po::options_description desc("Allowed options"); + desc.add_options() + ("help", "produce help message") + ("compression", po::value<int>(), "set compression level"); + + return desc; +}
\ No newline at end of file diff --git a/src/main/command_line_helper.h b/src/main/command_line_helper.h new file mode 100644 index 0000000..dc3b2b6 --- /dev/null +++ b/src/main/command_line_helper.h @@ -0,0 +1,12 @@ +// +// Created by thecharlesblake on 10/16/17. +// + +#ifndef SOLVITAIRE_COMMAND_LINE_HELPER_H +#define SOLVITAIRE_COMMAND_LINE_HELPER_H + +#include <boost/program_options.hpp> + +boost::program_options::options_description get_options_desc(); + +#endif //SOLVITAIRE_COMMAND_LINE_HELPER_H diff --git a/src/main/main.cpp b/src/main/main.cpp index e69de29..8c07d1f 100644 --- a/src/main/main.cpp +++ b/src/main/main.cpp @@ -0,0 +1,29 @@ +#include <boost/program_options.hpp> +#include <iostream> +#include "command_line_helper.h" + +using namespace std; + +namespace po = boost::program_options; + +int main(int argc, const char* argv[]) { + // Creates the command line options + po::options_description desc = get_options_desc(); + + po::variables_map vm; + po::store(po::parse_command_line(argc, argv, desc), vm); + po::notify(vm); + + if (vm.count("help")) { + cout << desc << "\n"; + return 1; + } + + if (vm.count("compression")) { + cout << "Compression level was set to " + << vm["compression"].as<int>() << ".\n"; + } else { + cout << "Compression level was not set.\n"; + } +} + |
