aboutsummaryrefslogtreecommitdiff
path: root/thirdparty/cxxopts/src/example.cpp
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2025-11-07 14:49:13 +0100
committerGitHub Enterprise <[email protected]>2025-11-07 14:49:13 +0100
commit24e43a913f29ac3b314354e8ce5175f135bcc64f (patch)
treeca442937ceeb63461012b33a4576e9835099f106 /thirdparty/cxxopts/src/example.cpp
parentget oplog attachments (#622) (diff)
downloadzen-24e43a913f29ac3b314354e8ce5175f135bcc64f.tar.xz
zen-24e43a913f29ac3b314354e8ce5175f135bcc64f.zip
switch to xmake for package management (#611)
This change removes our dependency on vcpkg for package management, in favour of bringing some code in-tree in the `thirdparty` folder as well as using the xmake build-in package management feature. For the latter, all the package definitions are maintained in the zen repo itself, in the `repo` folder. It should now also be easier to build the project as it will no longer depend on having the right version of vcpkg installed, which has been a common problem for new people coming in to the codebase. Now you should only need xmake to build. * Bumps xmake requirement on github runners to 2.9.9 to resolve an issue where xmake on Windows invokes cmake with `v144` toolchain which does not exist * BLAKE3 is now in-tree at `thirdparty/blake3` * cpr is now in-tree at `thirdparty/cpr` * cxxopts is now in-tree at `thirdparty/cxxopts` * fmt is now in-tree at `thirdparty/fmt` * robin-map is now in-tree at `thirdparty/robin-map` * ryml is now in-tree at `thirdparty/ryml` * sol2 is now in-tree at `thirdparty/sol2` * spdlog is now in-tree at `thirdparty/spdlog` * utfcpp is now in-tree at `thirdparty/utfcpp` * xmake package repo definitions is in `repo` * implemented support for sanitizers. ASAN is supported on windows, TSAN, UBSAN, MSAN etc are supported on Linux/MacOS though I have not yet tested it extensively on MacOS * the zencore encryption implementation also now supports using mbedTLS which is used on MacOS, though for now we still use openssl on Linux * crashpad * bumps libcurl to 8.11.0 (from 8.8.0) which should address a rare build upload bug
Diffstat (limited to 'thirdparty/cxxopts/src/example.cpp')
-rw-r--r--thirdparty/cxxopts/src/example.cpp202
1 files changed, 202 insertions, 0 deletions
diff --git a/thirdparty/cxxopts/src/example.cpp b/thirdparty/cxxopts/src/example.cpp
new file mode 100644
index 000000000..c6da3a002
--- /dev/null
+++ b/thirdparty/cxxopts/src/example.cpp
@@ -0,0 +1,202 @@
+/*
+
+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 "cxxopts.hpp"
+
+#include <iostream>
+#include <memory>
+
+int
+parse(int argc, const char* argv[])
+{
+ try
+ {
+ std::unique_ptr<cxxopts::Options> allocated(new cxxopts::Options(argv[0], " - example command line options"));
+ auto& options = *allocated;
+ options
+ .positional_help("[optional args]")
+ .show_positional_help();
+
+ bool apple = false;
+
+ options
+ .set_width(70)
+ .set_tab_expansion()
+ .allow_unrecognised_options()
+ .add_options()
+ ("a,apple,ringo", "an apple", cxxopts::value<bool>(apple))
+ ("b,bob", "Bob")
+ ("char", "A character", cxxopts::value<char>())
+ ("t,true", "True", cxxopts::value<bool>()->default_value("true"))
+ ("f, file", "File", cxxopts::value<std::vector<std::string>>(), "FILE")
+ ("i,input", "Input", cxxopts::value<std::string>())
+ ("o,output", "Output file", cxxopts::value<std::string>()
+ ->default_value("a.out")->implicit_value("b.def"), "BIN")
+ ("x", "A short-only option", cxxopts::value<std::string>())
+ ("positional",
+ "Positional arguments: these are the arguments that are entered "
+ "without an option", cxxopts::value<std::vector<std::string>>())
+ ("long-description",
+ "thisisareallylongwordthattakesupthewholelineandcannotbebrokenataspace")
+ ("help", "Print help")
+ ("tab-expansion", "Tab\texpansion")
+ ("int", "An integer", cxxopts::value<int>(), "N")
+ ("float", "A floating point number", cxxopts::value<float>())
+ ("vector", "A list of doubles", cxxopts::value<std::vector<double>>())
+ ("option_that_is_too_long_for_the_help", "A very long option")
+ ("l,list", "List all parsed arguments (including default values)")
+ ("range", "Use range-for to list arguments")
+ #ifdef CXXOPTS_USE_UNICODE
+ ("unicode", u8"A help option with non-ascii: à. Here the size of the"
+ " string should be correct")
+ #endif
+ ;
+
+ options.add_options("Group")
+ ("c,compile", "compile")
+ ("d,drop", "drop", cxxopts::value<std::vector<std::string>>());
+
+ options.parse_positional({"input", "output", "positional"});
+
+ auto result = options.parse(argc, argv);
+
+ if (result.count("help"))
+ {
+ std::cout << options.help({"", "Group"}) << std::endl;
+ return true;
+ }
+
+ if(result.count("list"))
+ {
+ if(result.count("range"))
+ {
+ for(const auto &kv: result)
+ {
+ std::cout << kv.key() << " = " << kv.value() << std::endl;
+ }
+ }
+ else
+ {
+ std::cout << result.arguments_string() << std::endl;
+ }
+ return true;
+ }
+
+ if (apple)
+ {
+ std::cout << "Saw option ‘a’ " << result.count("a") << " times " <<
+ std::endl;
+ }
+
+ if (result.count("b"))
+ {
+ std::cout << "Saw option ‘b’" << std::endl;
+ }
+
+ if (result.count("char"))
+ {
+ std::cout << "Saw a character ‘" << result["char"].as<char>() << "’" << std::endl;
+ }
+
+ if (result.count("f"))
+ {
+ auto& ff = result["f"].as<std::vector<std::string>>();
+ std::cout << "Files" << std::endl;
+ for (const auto& f : ff)
+ {
+ std::cout << f << std::endl;
+ }
+ }
+
+ if (result.count("input"))
+ {
+ std::cout << "Input = " << result["input"].as<std::string>()
+ << std::endl;
+ }
+
+ if (result.count("output"))
+ {
+ std::cout << "Output = " << result["output"].as<std::string>()
+ << std::endl;
+ }
+
+ if (result.count("positional"))
+ {
+ std::cout << "Positional = {";
+ auto& v = result["positional"].as<std::vector<std::string>>();
+ for (const auto& s : v) {
+ std::cout << s << ", ";
+ }
+ std::cout << "}" << std::endl;
+ }
+
+ if (result.count("int"))
+ {
+ std::cout << "int = " << result["int"].as<int>() << std::endl;
+ }
+
+ if (result.count("float"))
+ {
+ std::cout << "float = " << result["float"].as<float>() << std::endl;
+ }
+
+ if (result.count("vector"))
+ {
+ std::cout << "vector = ";
+ const auto values = result["vector"].as<std::vector<double>>();
+ for (const auto& v : values) {
+ std::cout << v << ", ";
+ }
+ std::cout << std::endl;
+ }
+
+ std::cout << "Arguments remain = " << argc << std::endl;
+
+ auto arguments = result.arguments();
+ std::cout << "Saw " << arguments.size() << " arguments" << std::endl;
+
+ std::cout << "Unmatched options: ";
+ for (const auto& option: result.unmatched())
+ {
+ std::cout << "'" << option << "' ";
+ }
+ std::cout << std::endl;
+ }
+ catch (const cxxopts::exceptions::exception& e)
+ {
+ std::cout << "error parsing options: " << e.what() << std::endl;
+ return false;
+ }
+
+ return true;
+}
+
+int main(int argc, const char* argv[])
+{
+ if (!parse(argc, argv))
+ {
+ return 1;
+ }
+
+ return 0;
+}