From 4e208b95b7ae488b0d31fcc80228b141792b79b5 Mon Sep 17 00:00:00 2001 From: Jarryd Beck Date: Fri, 14 Jan 2022 16:16:31 +1100 Subject: Add a program function Fixes 323. Adds a function to retrieve the program name. --- CHANGELOG.md | 6 ++++++ include/cxxopts.hpp | 5 +++++ test/options.cpp | 2 ++ 3 files changed, 13 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c50fae0..220717d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,12 @@ This is the changelog for `cxxopts`, a C++11 library for parsing command line options. The project adheres to semantic versioning. +## Unreleased + +### Added + +* Add a `program()` function to retrieve the program name. + ## 3.0 ### Changed diff --git a/include/cxxopts.hpp b/include/cxxopts.hpp index d247ba7..2dd4da6 100644 --- a/include/cxxopts.hpp +++ b/include/cxxopts.hpp @@ -1825,6 +1825,11 @@ namespace cxxopts const HelpGroupDetails& group_help(const std::string& group) const; + const std::string& program() const + { + return m_program; + } + private: void diff --git a/test/options.cpp b/test/options.cpp index 610a6bc..3398b70 100644 --- a/test/options.cpp +++ b/test/options.cpp @@ -95,6 +95,8 @@ TEST_CASE("Basic options", "[options]") CHECK(arguments[3].key() == "av"); CHECK_THROWS_AS(result["nothing"].as(), cxxopts::option_has_no_value_exception&); + + CHECK(options.program() == "tester"); } TEST_CASE("Short options", "[options]") -- cgit v1.2.3