From 100db357db00d6f3fb963f4661cdb20fd7b57aef Mon Sep 17 00:00:00 2001 From: Henry Fredrick Schreiner Date: Sun, 4 Jun 2017 11:29:42 -0400 Subject: [PATCH] Better example names --- examples/CMakeLists.txt | 6 +++--- examples/groups.cpp | 31 +++++++++++++++++++++++++++++++ examples/simple.cpp | 29 +++++++++++++++++++++++++++++ examples/subcommands.cpp | 27 +++++++++++++++++++++++++++ examples/try.cpp | 29 ----------------------------- examples/try1.cpp | 27 --------------------------- examples/try2.cpp | 31 ------------------------------- 7 files changed, 90 insertions(+), 90 deletions(-) create mode 100644 examples/groups.cpp create mode 100644 examples/simple.cpp create mode 100644 examples/subcommands.cpp delete mode 100644 examples/try.cpp delete mode 100644 examples/try1.cpp delete mode 100644 examples/try2.cpp diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index d08459a..b4efebd 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -14,6 +14,6 @@ function(add_cli_exe T) endif() endfunction() -add_cli_exe(try try.cpp) -add_cli_exe(try1 try1.cpp) -add_cli_exe(try2 try2.cpp) +add_cli_exe(simple simple.cpp) +add_cli_exe(subcommands subcommands.cpp) +add_cli_exe(groups groups.cpp) diff --git a/examples/groups.cpp b/examples/groups.cpp new file mode 100644 index 0000000..0b6b109 --- /dev/null +++ b/examples/groups.cpp @@ -0,0 +1,31 @@ +#include "CLI/CLI.hpp" +#include "CLI/Timer.hpp" + +int main(int argc, char **argv) { + CLI::AutoTimer("This is a timer"); + + CLI::App app("K3Pi goofit fitter"); + + std::string file; + CLI::Option *opt = app.add_option("-f,--file,file", file, "File name")->required()->group("Important"); + + int count; + CLI::Option *copt = app.add_flag("-c,--count", count, "Counter")->required()->group("Important"); + + double value; // = 3.14; + app.add_option("-d,--double", value, "Some Value")->group("Other"); + + try { + app.parse(argc, argv); + } catch(const CLI::Error &e) { + return app.exit(e); + } + + std::cout << "Working on file: " << file << ", direct count: " << app.count("--file") + << ", opt count: " << opt->count() << std::endl; + std::cout << "Working on count: " << count << ", direct count: " << app.count("--count") + << ", opt count: " << copt->count() << std::endl; + std::cout << "Some value: " << value << std::endl; + + return 0; +} diff --git a/examples/simple.cpp b/examples/simple.cpp new file mode 100644 index 0000000..505af06 --- /dev/null +++ b/examples/simple.cpp @@ -0,0 +1,29 @@ +#include "CLI/CLI.hpp" + +int main(int argc, char **argv) { + + CLI::App app("K3Pi goofit fitter"); + + std::string file; + CLI::Option *opt = app.add_option("-f,--file,file", file, "File name"); + + int count; + CLI::Option *copt = app.add_flag("-c,--count", count, "Counter"); + + double value; // = 3.14; + app.add_option("-d,--double", value, "Some Value"); + + try { + app.parse(argc, argv); + } catch(const CLI::Error &e) { + return app.exit(e); + } + + std::cout << "Working on file: " << file << ", direct count: " << app.count("--file") + << ", opt count: " << opt->count() << std::endl; + std::cout << "Working on count: " << count << ", direct count: " << app.count("--count") + << ", opt count: " << copt->count() << std::endl; + std::cout << "Some value: " << value << std::endl; + + return 0; +} diff --git a/examples/subcommands.cpp b/examples/subcommands.cpp new file mode 100644 index 0000000..39bc7eb --- /dev/null +++ b/examples/subcommands.cpp @@ -0,0 +1,27 @@ +#include "CLI/CLI.hpp" + +int main(int argc, char **argv) { + + CLI::App app("K3Pi goofit fitter"); + app.add_flag("--random", "Some random flag"); + CLI::App *start = app.add_subcommand("start", "A great subcommand"); + CLI::App *stop = app.add_subcommand("stop", "Do you really want to stop?"); + + std::string file; + start->add_option("-f,--file", file, "File name"); + + CLI::Option *s = stop->add_flag("-c,--count", "Counter"); + + try { + app.parse(argc, argv); + } catch(const CLI::Error &e) { + return app.exit(e); + } + + std::cout << "Working on file: " << file << ", direct count: " << start->count("--file") << std::endl; + std::cout << "Working on count: " << s->count() << ", direct count: " << stop->count("--count") << std::endl; + for(auto subcom : app.get_subcommands()) + std::cout << "Subcommand:" << subcom->get_name() << std::endl; + + return 0; +} diff --git a/examples/try.cpp b/examples/try.cpp deleted file mode 100644 index 505af06..0000000 --- a/examples/try.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include "CLI/CLI.hpp" - -int main(int argc, char **argv) { - - CLI::App app("K3Pi goofit fitter"); - - std::string file; - CLI::Option *opt = app.add_option("-f,--file,file", file, "File name"); - - int count; - CLI::Option *copt = app.add_flag("-c,--count", count, "Counter"); - - double value; // = 3.14; - app.add_option("-d,--double", value, "Some Value"); - - try { - app.parse(argc, argv); - } catch(const CLI::Error &e) { - return app.exit(e); - } - - std::cout << "Working on file: " << file << ", direct count: " << app.count("--file") - << ", opt count: " << opt->count() << std::endl; - std::cout << "Working on count: " << count << ", direct count: " << app.count("--count") - << ", opt count: " << copt->count() << std::endl; - std::cout << "Some value: " << value << std::endl; - - return 0; -} diff --git a/examples/try1.cpp b/examples/try1.cpp deleted file mode 100644 index 39bc7eb..0000000 --- a/examples/try1.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include "CLI/CLI.hpp" - -int main(int argc, char **argv) { - - CLI::App app("K3Pi goofit fitter"); - app.add_flag("--random", "Some random flag"); - CLI::App *start = app.add_subcommand("start", "A great subcommand"); - CLI::App *stop = app.add_subcommand("stop", "Do you really want to stop?"); - - std::string file; - start->add_option("-f,--file", file, "File name"); - - CLI::Option *s = stop->add_flag("-c,--count", "Counter"); - - try { - app.parse(argc, argv); - } catch(const CLI::Error &e) { - return app.exit(e); - } - - std::cout << "Working on file: " << file << ", direct count: " << start->count("--file") << std::endl; - std::cout << "Working on count: " << s->count() << ", direct count: " << stop->count("--count") << std::endl; - for(auto subcom : app.get_subcommands()) - std::cout << "Subcommand:" << subcom->get_name() << std::endl; - - return 0; -} diff --git a/examples/try2.cpp b/examples/try2.cpp deleted file mode 100644 index 0b6b109..0000000 --- a/examples/try2.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include "CLI/CLI.hpp" -#include "CLI/Timer.hpp" - -int main(int argc, char **argv) { - CLI::AutoTimer("This is a timer"); - - CLI::App app("K3Pi goofit fitter"); - - std::string file; - CLI::Option *opt = app.add_option("-f,--file,file", file, "File name")->required()->group("Important"); - - int count; - CLI::Option *copt = app.add_flag("-c,--count", count, "Counter")->required()->group("Important"); - - double value; // = 3.14; - app.add_option("-d,--double", value, "Some Value")->group("Other"); - - try { - app.parse(argc, argv); - } catch(const CLI::Error &e) { - return app.exit(e); - } - - std::cout << "Working on file: " << file << ", direct count: " << app.count("--file") - << ", opt count: " << opt->count() << std::endl; - std::cout << "Working on count: " << count << ", direct count: " << app.count("--count") - << ", opt count: " << copt->count() << std::endl; - std::cout << "Some value: " << value << std::endl; - - return 0; -} -- libgit2 0.21.4