jackett 0.22.1382
[Homebrew/homebrew-core.git] / Formula / c / cxxopts.rb
blob97ba5cdd48495a184fee16668040b862e002d7a3
1 class Cxxopts < Formula
2   desc "Lightweight C++ command-line option parser"
3   homepage "https://github.com/jarro2783/cxxopts"
4   url "https://github.com/jarro2783/cxxopts/archive/refs/tags/v3.2.1.tar.gz"
5   sha256 "841f49f2e045b9c6365997c2a8fbf76e6f215042dda4511a5bb04bc5ebc7f88a"
6   license "MIT"
7   head "https://github.com/jarro2783/cxxopts.git", branch: "master"
9   bottle do
10     sha256 cellar: :any_skip_relocation, all: "883a901ef150f303dfba9430fc0fd7f29a9f132406b35ebd9dcf481f23029957"
11   end
13   depends_on "cmake" => :build
15   def install
16     args = %w[
17       -DCXXOPTS_BUILD_EXAMPLES=OFF
18       -DCXXOPTS_BUILD_TESTS=OFF
19     ]
21     system "cmake", "-S", ".", "-B", "build", *args, *std_cmake_args
22     system "cmake", "--build", "build"
23     system "cmake", "--install", "build"
24   end
26   test do
27     (testpath/"test.cc").write <<~CPP
28       #include <iostream>
29       #include <cstdlib>
30       #include <cxxopts.hpp>
32       int main(int argc, char *argv[]) {
33           cxxopts::Options options(argv[0]);
35           std::string input;
36           options.add_options()
37               ("e,echo", "String to be echoed", cxxopts::value(input))
38               ("h,help", "Print this help", cxxopts::value<bool>()->default_value("false"));
40           auto result = options.parse(argc, argv);
42           if (result.count("help")) {
43               std::cout << options.help() << std::endl;
44               std::exit(0);
45           }
47           std::cout << input << std::endl;
49           return 0;
50       }
51     CPP
53     system ENV.cxx, "-std=c++11", "test.cc", "-I#{include}", "-o", "test"
54     assert_equal "echo string", shell_output("./test -e 'echo string'").strip
55     assert_equal "echo string", shell_output("./test --echo='echo string'").strip
56   end
57 end