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