From def4848b23ef699ab05d477ca5fad1034a685f8d Mon Sep 17 00:00:00 2001 From: Jarryd Beck Date: Fri, 10 Oct 2014 18:03:44 +1100 Subject: [PATCH] move to example.cpp --- src/CMakeLists.txt | 2 +- src/example.cpp | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/main.cpp | 88 ---------------------------------------------------------------------------------------- 3 files changed, 89 insertions(+), 89 deletions(-) create mode 100644 src/example.cpp delete mode 100644 src/main.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 53b763d..d07c999 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -18,7 +18,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -add_executable(example main.cpp) +add_executable(example example.cpp) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall") diff --git a/src/example.cpp b/src/example.cpp new file mode 100644 index 0000000..1ab28ef --- /dev/null +++ b/src/example.cpp @@ -0,0 +1,88 @@ +/* + +Copyright (c) 2014 Jarryd Beck + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + +*/ + +#include + +#include "cxxopts.hpp" + +int main(int argc, char* argv[]) +{ + try + { + + cxxopts::Options options; + + options.add_options() + ("a,apple", "an apple") + ("b,bob", "Bob") + ("f,file", "File", cxxopts::value>()) + ("positional", "Positional arguments", cxxopts::value()) + ("help", "Print help") + ; + + options.parse_positional("positional"); + + options.parse(argc, argv); + + if (options.count("a")) + { + std::cout << "Saw option ‘a’" << std::endl; + } + + if (options.count("b")) + { + std::cout << "Saw option ‘b’" << std::endl; + } + + if (options.count("f")) + { + auto& ff = options["f"].as>(); + std::cout << "Files" << std::endl; + for (const auto& f : ff) + { + std::cout << f << std::endl; + } + } + + if (options.count("help")) + { + std::cout << options.help() << std::endl; + } + + if (options.count("positional")) + { + std::cout << "Positional = " << options["positional"].as() + << std::endl; + } + + std::cout << argc << std::endl; + + } catch (const cxxopts::OptionException& e) + { + std::cout << "error parsing options: " << e.what() << std::endl; + exit(1); + } + + return 0; +} diff --git a/src/main.cpp b/src/main.cpp deleted file mode 100644 index 1ab28ef..0000000 --- a/src/main.cpp +++ /dev/null @@ -1,88 +0,0 @@ -/* - -Copyright (c) 2014 Jarryd Beck - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. - -*/ - -#include - -#include "cxxopts.hpp" - -int main(int argc, char* argv[]) -{ - try - { - - cxxopts::Options options; - - options.add_options() - ("a,apple", "an apple") - ("b,bob", "Bob") - ("f,file", "File", cxxopts::value>()) - ("positional", "Positional arguments", cxxopts::value()) - ("help", "Print help") - ; - - options.parse_positional("positional"); - - options.parse(argc, argv); - - if (options.count("a")) - { - std::cout << "Saw option ‘a’" << std::endl; - } - - if (options.count("b")) - { - std::cout << "Saw option ‘b’" << std::endl; - } - - if (options.count("f")) - { - auto& ff = options["f"].as>(); - std::cout << "Files" << std::endl; - for (const auto& f : ff) - { - std::cout << f << std::endl; - } - } - - if (options.count("help")) - { - std::cout << options.help() << std::endl; - } - - if (options.count("positional")) - { - std::cout << "Positional = " << options["positional"].as() - << std::endl; - } - - std::cout << argc << std::endl; - - } catch (const cxxopts::OptionException& e) - { - std::cout << "error parsing options: " << e.what() << std::endl; - exit(1); - } - - return 0; -} -- libgit2 0.21.4