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

Compare commits

...

4 Commits

Author SHA1 Message Date
Henry Schreiner
7cdd95e312 chore: update pre-commit and GHA 2020-07-27 22:11:23 -04:00
Henry Schreiner
99a8edcfcd docs: update validator 2020-07-27 22:11:23 -04:00
Henry Schreiner
f1349f12e3 Bump to Version 1.9.1 2020-07-27 22:11:23 -04:00
Philip Top
102e201dc7
fix: a failing test case for toml string_vector processing (#491) 2020-07-27 22:10:18 -04:00
8 changed files with 65 additions and 22 deletions

View File

@ -1,8 +1,9 @@
version: 1.9.0.{build}
version: 1.9.1.{build}
branches:
only:
- master
- v1
install:
- git submodule update --init --recursive

View File

@ -16,11 +16,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2
with:
submodules: true
- uses: actions/setup-python@v1
- uses: actions/setup-python@v2
- name: Make header
run: python ./scripts/MakeSingleHeader.py CLI11.hpp
@ -37,12 +37,12 @@ jobs:
cp build/CLI11-*-Source.* CLI11-Source
cp build/CLI11-*-Source.* .
- uses: actions/upload-artifact@v1
- uses: actions/upload-artifact@v2
with:
name: CLI11.hpp
path: CLI11.hpp
- uses: actions/upload-artifact@v1
- uses: actions/upload-artifact@v2
with:
name: CLI11-Source
path: CLI11-Source

View File

@ -27,8 +27,8 @@ jobs:
submodules: true
- name: Add wget
run: apt-get update && apt-get install -y wget
- name: Install Modern CMake
run: wget -qO- "https://cmake.org/files/v3.16/cmake-3.16.0-Linux-x86_64.tar.gz" | tar --strip-components=1 -xz -C /usr/local
- name: Setup cmake
uses: jwlawson/actions-setup-cmake@v1.3
- name: Configure
run: cmake -S . -B build -DCLI11_CUDA_TESTS=ON
- name: Build
@ -38,7 +38,7 @@ jobs:
name: CMake config check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2
with:
submodules: true
- name: CMake 3.4
@ -106,9 +106,14 @@ jobs:
with:
version: 3.16.8
if: success() || failure()
- name: CMake 3.16 (full)
- name: CMake 3.17
uses: ./.github/actions/cmake_config
with:
version: 3.17.3
if: success() || failure()
- name: CMake 3.18 (full)
uses: ./.github/actions/cmake_config
with:
version: 3.18.0
options: -DCLI11_SANITIZERS=ON -DCLI11_BUILD_EXAMPLES_JSON=ON
if: success() || failure()

View File

@ -1,11 +1,11 @@
repos:
- repo: https://github.com/psf/black
rev: 19.3b0
rev: 19.10b0
hooks:
- id: black
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
rev: v3.1.0
hooks:
- id: check-added-large-files
- id: mixed-line-ending

View File

@ -1,9 +1,5 @@
# Validators
{% hint style='info' %}
Improved in CLI11 1.6
{% endhint %}
There are two forms of validators:
* `transform` validators: mutating
@ -15,9 +11,9 @@ the function should throw a `CLI::ValidationError` with the appropriate reason a
However, `check` validators come in two forms; either a simple function with the const version of the
above signature, `std::string(const std::string &)`, or a subclass of `struct CLI::Validator`. This
structure has two members that a user should set; one (`func`) is the function to add to the Option
structure has two members that a user should set; one (`func_`) is the function to add to the Option
(exactly matching the above function signature, since it will become that function), and the other is
`tname`, and is the type name to set on the Option (unless empty, in which case the typename will be
`name_`, and is the type name to set on the Option (unless empty, in which case the typename will be
left unchanged).
Validators can be combined with `&` and `|`, and they have an `operator()` so that you can call them
@ -29,8 +25,8 @@ An example of a custom validator:
```cpp
struct LowerCaseValidator : public Validator {
LowerCaseValidator() {
tname = "LOWER";
func = [](const std::string &str) {
name_ = "LOWER";
func_ = [](const std::string &str) {
if(CLI::detail::to_lower(str) != str)
return std::string("String is not lower case");
else
@ -54,3 +50,15 @@ The built-in validators for CLI11 are:
| `Range(min=0, max)` | Produce a range (factory). Min and max are inclusive. |
And, the protected members that you can set when you make your own are:
| Type | Member | Description |
|------|--------|-------------|
| `std::function<std::string(std::string &)>` | `func_` | Core validation function - modifies input and returns "" if successful |
| `std::function<std::string()>` | `desc_function` | Optional description function (uses `description_` instead if not set) |
| `std::string` | `name_` | The name for search purposes |
| `int` (`-1`) | `application_index_` | The element this validator applies to (-1 for all) |
| `bool` (`true`) | `active_` | This can be disabled |
| `bool` (`false`) | `non_modifying_` | Specify that this is a Validator instead of a Transformer |

View File

@ -310,7 +310,12 @@ inline std::vector<std::string> split_up(std::string str, char delimiter = '\0')
}
if(end != std::string::npos) {
output.push_back(str.substr(1, end - 1));
str = str.substr(end + 1);
if(end + 2 < str.size()) {
str = str.substr(end + 2);
} else {
str.clear();
}
} else {
output.push_back(str.substr(1));
str = "";

View File

@ -10,7 +10,7 @@
#define CLI11_VERSION_MAJOR 1
#define CLI11_VERSION_MINOR 9
#define CLI11_VERSION_PATCH 0
#define CLI11_VERSION "1.9.0"
#define CLI11_VERSION_PATCH 1
#define CLI11_VERSION "1.9.1"
// [CLI11:verbatim]

View File

@ -770,6 +770,30 @@ TEST_F(TApp, TOMLVectordirect) {
EXPECT_EQ(std::vector<int>({1, 2, 3}), three);
}
TEST_F(TApp, TOMLStringVector) {
TempFile tmptoml{"TestTomlTmp.toml"};
app.set_config("--config", tmptoml);
{
std::ofstream out{tmptoml};
out << "#this is a comment line\n";
out << "[default]\n";
out << "two=[\"2\",\"3\"]\n";
out << "three=[\"1\",\"2\",\"3\"]\n";
}
std::vector<std::string> two, three;
app.add_option("--two", two)->required();
app.add_option("--three", three)->required();
run();
EXPECT_EQ(std::vector<std::string>({"2", "3"}), two);
EXPECT_EQ(std::vector<std::string>({"1", "2", "3"}), three);
}
TEST_F(TApp, IniVectorCsep) {
TempFile tmpini{"TestIniTmp.ini"};