1
0
mirror of https://github.com/CLIUtils/CLI11.git synced 2025-01-15 14:48:00 +00:00

Compare commits

...

5 Commits

Author SHA1 Message Date
Henry Schreiner
706b14fb14
Fix formatting 2020-01-31 13:56:15 -05:00
Henry Schreiner
63c928653b
Remove invalid comment
[skip ci]
2020-01-31 13:50:15 -05:00
Henry Schreiner
b5242611a5
Minor packaging cleanup 2020-01-31 13:49:16 -05:00
Henry Schreiner
9549c6287f
Clean up sdist creation (#422)
* Adding package to release

* Fix build.yml

* Update build.yml

* Update build.yml

* Update build.yml

* Update build.yml

* Cleaner, tigher packages

* Do not add package to release
2020-01-31 13:17:11 -05:00
Philip Top
ee851c7e88
String conversions (#421)
* add a variant of the string conversions for the default string operations.  Discriminate between the is_convertible and is_constructible type traits for object.

* update the test to test the different situations with the funny string like type
2020-01-31 07:49:40 -05:00
4 changed files with 71 additions and 8 deletions

View File

@ -17,20 +17,41 @@ jobs:
steps:
- uses: actions/checkout@v1
with:
submodules: true
- uses: actions/setup-python@v1
- name: Make header
run: python ./scripts/MakeSingleHeader.py CLI11.hpp
- name: Prepare CMake config
run: cmake -S . -B build
- name: Make package
run: cmake --build build --target package_source
- name: Copy source packages
run: |
mkdir -p CLI11-Source
cp build/CLI11-*-Source.* CLI11-Source
cp build/CLI11-*-Source.* .
- uses: actions/upload-artifact@v1
with:
name: CLI11.hpp
path: CLI11.hpp
- uses: actions/upload-artifact@v1
with:
name: CLI11-Source
path: CLI11-Source
- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: CLI11.hpp
files: |
CLI11.hpp
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@ -268,16 +268,18 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND EXISTS "${CMAKE_CURRENT_SOURCE_D
add_subdirectory(book)
endif()
# Packaging support
# Packaging support
set(CPACK_PACKAGE_VENDOR "github.com/CLIUtils/CLI11")
set(CPACK_PACKAGE_CONTACT "https://${CPACK_PACKAGE_VENDOR}")
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR}) # Automatic in CMake 3.12+
set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR}) # Automatic in CMake 3.12+
set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH}) # Automatic in CMake 3.12+
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Command line parser with simple and intuitive interface")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/CLI11.CPack.Description.txt")
set(CPACK_SOURCE_GENERATOR "TGZ;ZIP")
# CPack collects *everything* except what's listed here.
set(CPACK_SOURCE_IGNORE_FILES
/.git
@ -286,12 +288,22 @@ set(CPACK_SOURCE_IGNORE_FILES
/\\\\.DS_Store
/.*\\\\.egg-info
/var
/Pipfile.*$
/azure-pipelines.yml
/.ci
/docs
/examples
/test_package
/book
/.travis.yml
.swp
/.all-contributorsrc
/.appveyor.yml
/.pre-commit.*yaml
)
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "all")
set(CPACK_DEBIAN_COMPRESSION_TYPE "xz")
set(CPACK_DEBIAN_PACKAGE_NAME "libcli11-dev")
include(CPack)

View File

@ -219,15 +219,24 @@ template <typename S> class is_tuple_like {
};
/// Convert an object to a string (directly forward if this can become a string)
template <typename T, enable_if_t<std::is_constructible<std::string, T>::value, detail::enabler> = detail::dummy>
template <typename T, enable_if_t<std::is_convertible<T, std::string>::value, detail::enabler> = detail::dummy>
auto to_string(T &&value) -> decltype(std::forward<T>(value)) {
return std::forward<T>(value);
}
/// Construct a string from the object
template <typename T,
enable_if_t<std::is_constructible<std::string, T>::value && !std::is_convertible<T, std::string>::value,
detail::enabler> = detail::dummy>
std::string to_string(const T &value) {
return std::string(value);
}
/// Convert an object to a string (streaming must be supported for that type)
template <typename T,
enable_if_t<!std::is_constructible<std::string, T>::value && is_ostreamable<T>::value, detail::enabler> =
detail::dummy>
enable_if_t<!std::is_convertible<std::string, T>::value && !std::is_constructible<std::string, T>::value &&
is_ostreamable<T>::value,
detail::enabler> = detail::dummy>
std::string to_string(T &&value) {
std::stringstream stream;
stream << value;

View File

@ -1885,6 +1885,27 @@ TEST_F(TApp, VectorUnlimString) {
EXPECT_EQ(answer, strvec);
}
// From https://github.com/CLIUtils/CLI11/issues/420
TEST_F(TApp, stringLikeTests) {
struct nType {
explicit nType(const std::string &a_value) : m_value{a_value} {}
explicit operator std::string() const { return std::string{"op str"}; }
std::string m_value;
};
nType m_type{"abc"};
app.add_option("--type", m_type, "type")->capture_default_str();
run();
EXPECT_EQ(app["--type"]->as<std::string>(), "op str");
args = {"--type", "bca"};
run();
EXPECT_EQ(std::string(m_type), "op str");
EXPECT_EQ(m_type.m_value, "bca");
}
TEST_F(TApp, VectorExpectedRange) {
std::vector<std::string> strvec;