Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
302302b308 | ||
|
|
5ce83d014c | ||
|
|
94c09511dd | ||
|
|
56432321b8 | ||
|
|
c4bd30be57 |
12
CHANGELOG.md
12
CHANGELOG.md
@ -3,6 +3,18 @@
|
||||
This is the changelog for `cxxopts`, a C++11 library for parsing command line
|
||||
options. The project adheres to semantic versioning.
|
||||
|
||||
## 2.2.1
|
||||
|
||||
### Changed
|
||||
|
||||
* Only search for a C++ compiler in CMakeLists.txt.
|
||||
* Allow installing to be disabled.
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Fix error printing long help lines.
|
||||
* Fix duplicate default options when there is a short and long option.
|
||||
|
||||
## 2.2
|
||||
|
||||
### Changed
|
||||
|
||||
@ -30,12 +30,13 @@ endforeach()
|
||||
set(VERSION ${CXXOPTS__VERSION_MAJOR}.${CXXOPTS__VERSION_MINOR}.${CXXOPTS__VERSION_PATCH})
|
||||
message(STATUS "cxxopts version ${VERSION}")
|
||||
|
||||
project(cxxopts VERSION "${VERSION}")
|
||||
project(cxxopts VERSION "${VERSION}" LANGUAGES CXX)
|
||||
|
||||
enable_testing()
|
||||
|
||||
option(CXXOPTS_BUILD_EXAMPLES "Set to ON to build examples" ON)
|
||||
option(CXXOPTS_BUILD_TESTS "Set to ON to build tests" ON)
|
||||
option(CXXOPTS_ENABLE_INSTALL "Generate the install target" ON)
|
||||
|
||||
# request c++11 without gnu extension for the whole project and enable more warnings
|
||||
if (CXXOPTS_CXX_STANDARD)
|
||||
@ -70,35 +71,37 @@ target_include_directories(cxxopts INTERFACE
|
||||
$<INSTALL_INTERFACE:include>
|
||||
)
|
||||
|
||||
include(CMakePackageConfigHelpers)
|
||||
set(CXXOPTS_CMAKE_DIR "lib/cmake/cxxopts" CACHE STRING
|
||||
if(CXXOPTS_ENABLE_INSTALL)
|
||||
include(CMakePackageConfigHelpers)
|
||||
set(CXXOPTS_CMAKE_DIR "lib/cmake/cxxopts" CACHE STRING
|
||||
"Installation directory for cmake files, relative to ${CMAKE_INSTALL_PREFIX}.")
|
||||
set(version_config "${PROJECT_BINARY_DIR}/cxxopts-config-version.cmake")
|
||||
set(project_config "${PROJECT_BINARY_DIR}/cxxopts-config.cmake")
|
||||
set(targets_export_name cxxopts-targets)
|
||||
set(version_config "${PROJECT_BINARY_DIR}/cxxopts-config-version.cmake")
|
||||
set(project_config "${PROJECT_BINARY_DIR}/cxxopts-config.cmake")
|
||||
set(targets_export_name cxxopts-targets)
|
||||
|
||||
# Generate the version, config and target files into the build directory.
|
||||
write_basic_package_version_file(
|
||||
# Generate the version, config and target files into the build directory.
|
||||
write_basic_package_version_file(
|
||||
${version_config}
|
||||
VERSION ${VERSION}
|
||||
COMPATIBILITY AnyNewerVersion)
|
||||
configure_package_config_file(
|
||||
configure_package_config_file(
|
||||
${PROJECT_SOURCE_DIR}/cxxopts-config.cmake.in
|
||||
${project_config}
|
||||
INSTALL_DESTINATION ${CXXOPTS_CMAKE_DIR})
|
||||
export(TARGETS cxxopts NAMESPACE cxxopts::
|
||||
export(TARGETS cxxopts NAMESPACE cxxopts::
|
||||
FILE ${PROJECT_BINARY_DIR}/${targets_export_name}.cmake)
|
||||
|
||||
# Install version, config and target files.
|
||||
install(
|
||||
# Install version, config and target files.
|
||||
install(
|
||||
FILES ${project_config} ${version_config}
|
||||
DESTINATION ${CXXOPTS_CMAKE_DIR})
|
||||
install(EXPORT ${targets_export_name} DESTINATION ${CXXOPTS_CMAKE_DIR}
|
||||
install(EXPORT ${targets_export_name} DESTINATION ${CXXOPTS_CMAKE_DIR}
|
||||
NAMESPACE cxxopts::)
|
||||
|
||||
# Install the header file and export the target
|
||||
install(TARGETS cxxopts EXPORT ${targets_export_name} DESTINATION lib)
|
||||
install(FILES ${PROJECT_SOURCE_DIR}/include/cxxopts.hpp DESTINATION include)
|
||||
# Install the header file and export the target
|
||||
install(TARGETS cxxopts EXPORT ${targets_export_name} DESTINATION lib)
|
||||
install(FILES ${PROJECT_SOURCE_DIR}/include/cxxopts.hpp DESTINATION include)
|
||||
endif()
|
||||
|
||||
add_subdirectory(src)
|
||||
add_subdirectory(test)
|
||||
|
||||
@ -1054,15 +1054,23 @@ namespace cxxopts
|
||||
parse_default(std::shared_ptr<const OptionDetails> details)
|
||||
{
|
||||
ensure_value(details);
|
||||
m_default = true;
|
||||
m_value->parse();
|
||||
}
|
||||
|
||||
size_t
|
||||
count() const
|
||||
count() const noexcept
|
||||
{
|
||||
return m_count;
|
||||
}
|
||||
|
||||
// TODO: maybe default options should count towards the number of arguments
|
||||
bool
|
||||
has_default() const noexcept
|
||||
{
|
||||
return m_default;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
const T&
|
||||
as() const
|
||||
@ -1090,6 +1098,7 @@ namespace cxxopts
|
||||
|
||||
std::shared_ptr<Value> m_value;
|
||||
size_t m_count = 0;
|
||||
bool m_default = false;
|
||||
};
|
||||
|
||||
class KeyValue
|
||||
@ -1475,6 +1484,7 @@ namespace cxxopts
|
||||
stringAppend(result, "\n");
|
||||
stringAppend(result, start, ' ');
|
||||
startLine = lastSpace + 1;
|
||||
lastSpace = startLine;
|
||||
}
|
||||
size = 0;
|
||||
}
|
||||
@ -1858,7 +1868,7 @@ ParseResult::parse(int& argc, char**& argv)
|
||||
|
||||
auto& store = m_results[detail];
|
||||
|
||||
if(!store.count() && value.has_default()){
|
||||
if(value.has_default() && !store.count() && !store.has_default()){
|
||||
parse_default(detail);
|
||||
}
|
||||
}
|
||||
|
||||
@ -315,8 +315,10 @@ TEST_CASE("Default values", "[default]")
|
||||
{
|
||||
cxxopts::Options options("defaults", "has defaults");
|
||||
options.add_options()
|
||||
("default", "Has implicit", cxxopts::value<int>()
|
||||
->default_value("42"));
|
||||
("default", "Has implicit", cxxopts::value<int>()->default_value("42"))
|
||||
("v,vector", "Default vector", cxxopts::value<std::vector<int>>()
|
||||
->default_value("1,4"))
|
||||
;
|
||||
|
||||
SECTION("Sets defaults") {
|
||||
Argv av({"implicit"});
|
||||
@ -327,6 +329,11 @@ TEST_CASE("Default values", "[default]")
|
||||
auto result = options.parse(argc, argv);
|
||||
CHECK(result.count("default") == 0);
|
||||
CHECK(result["default"].as<int>() == 42);
|
||||
|
||||
auto& v = result["vector"].as<std::vector<int>>();
|
||||
REQUIRE(v.size() == 2);
|
||||
CHECK(v[0] == 1);
|
||||
CHECK(v[1] == 4);
|
||||
}
|
||||
|
||||
SECTION("When values provided") {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user