From 9101c98f951e7b104e6969fd5984379ca04745ea Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Mon, 16 Oct 2017 14:15:25 +0100 Subject: Add demo command line parsing --- src/main/command_line_helper.cpp | 18 ++++++++++++++++++ src/main/command_line_helper.h | 12 ++++++++++++ src/main/main.cpp | 29 +++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 src/main/command_line_helper.cpp create mode 100644 src/main/command_line_helper.h (limited to 'src/main') 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 + +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(), "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::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 +#include +#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() << ".\n"; + } else { + cout << "Compression level was not set.\n"; + } +} + -- cgit v1.2.1