Commit 4e208b95b7ae488b0d31fcc80228b141792b79b5

Authored by Jarryd Beck
1 parent ad2d1a6b

Add a program function

Fixes 323. Adds a function to retrieve the program name.
CHANGELOG.md
@@ -3,6 +3,12 @@ @@ -3,6 +3,12 @@
3 This is the changelog for `cxxopts`, a C++11 library for parsing command line 3 This is the changelog for `cxxopts`, a C++11 library for parsing command line
4 options. The project adheres to semantic versioning. 4 options. The project adheres to semantic versioning.
5 5
  6 +## Unreleased
  7 +
  8 +### Added
  9 +
  10 +* Add a `program()` function to retrieve the program name.
  11 +
6 ## 3.0 12 ## 3.0
7 13
8 ### Changed 14 ### Changed
include/cxxopts.hpp
@@ -1825,6 +1825,11 @@ namespace cxxopts @@ -1825,6 +1825,11 @@ namespace cxxopts
1825 const HelpGroupDetails& 1825 const HelpGroupDetails&
1826 group_help(const std::string& group) const; 1826 group_help(const std::string& group) const;
1827 1827
  1828 + const std::string& program() const
  1829 + {
  1830 + return m_program;
  1831 + }
  1832 +
1828 private: 1833 private:
1829 1834
1830 void 1835 void
test/options.cpp
@@ -95,6 +95,8 @@ TEST_CASE("Basic options", "[options]") @@ -95,6 +95,8 @@ TEST_CASE("Basic options", "[options]")
95 CHECK(arguments[3].key() == "av"); 95 CHECK(arguments[3].key() == "av");
96 96
97 CHECK_THROWS_AS(result["nothing"].as<std::string>(), cxxopts::option_has_no_value_exception&); 97 CHECK_THROWS_AS(result["nothing"].as<std::string>(), cxxopts::option_has_no_value_exception&);
  98 +
  99 + CHECK(options.program() == "tester");
98 } 100 }
99 101
100 TEST_CASE("Short options", "[options]") 102 TEST_CASE("Short options", "[options]")