homebrew-core/Formula/cxxopts.rb

58 lines
1.7 KiB
Ruby

class Cxxopts < Formula
desc "Lightweight C++ command-line option parser"
homepage "https://github.com/jarro2783/cxxopts"
url "https://github.com/jarro2783/cxxopts/archive/v3.1.0.tar.gz"
sha256 "0a4518130cfb7284d069327e5b4574f6fb16c53e6ed7152f0b68200059d639f6"
license "MIT"
head "https://github.com/jarro2783/cxxopts.git", branch: "master"
bottle do
sha256 cellar: :any_skip_relocation, all: "2de1822f5826d1f8ae4e7b34fa0c1c7205526fdc66bd2ecfd3afe330aa8d9726"
end
depends_on "cmake" => :build
def install
ENV.cxx11
mkdir "build" do
system "cmake", "..", *std_cmake_args,
"-DCXXOPTS_BUILD_EXAMPLES=OFF",
"-DCXXOPTS_BUILD_TESTS=OFF"
system "make", "install"
end
end
test do
(testpath/"test.cc").write <<~EOS
#include <iostream>
#include <cstdlib>
#include <cxxopts.hpp>
int main(int argc, char *argv[]) {
cxxopts::Options options(argv[0]);
std::string input;
options.add_options()
("e,echo", "String to be echoed", cxxopts::value(input))
("h,help", "Print this help", cxxopts::value<bool>()->default_value("false"));
auto result = options.parse(argc, argv);
if (result.count("help")) {
std::cout << options.help() << std::endl;
std::exit(0);
}
std::cout << input << std::endl;
return 0;
}
EOS
system ENV.cxx, "-std=c++11", "test.cc", "-I#{include}", "-o", "test"
assert_equal "echo string", shell_output("./test -e 'echo string'").strip
assert_equal "echo string", shell_output("./test --echo='echo string'").strip
end
end