Skip to content
Snippets Groups Projects
Commit da523f3d authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

git subrepo commit packages/CLI11

subrepo:
  subdir:   "packages/CLI11"
  merged:   "76d2cde65"
upstream:
  origin:   "git@github.com:CLIUtils/CLI11.git"
  branch:   "master"
  commit:   "76d2cde65"
git-subrepo:
  version:  "0.4.0"
  origin:   "git@github.com:ingydotnet/git-subrepo.git"
  commit:   "5d6aba9"
parent ead793c3
No related branches found
No related tags found
No related merge requests found
Showing
with 827 additions and 113 deletions
steps:
- checkout: self
fetchDepth: 50
submodules: true
- task: CMake@1
inputs:
cmakeArgs: .. -DCLI12_SINGLE_FILE=ON -DCLI11_CXX_STD=14 -DCLI11_SINGLE_FILE_TESTS=ON -DCMAKE_BUILD_TYPE=Debug
displayName: 'Configure'
- script: cmake --build . -j
displayName: 'Build'
workingDirectory: build
- script: ctest --output-on-failure -C Debug
displayName: 'Test'
workingDirectory: build
......@@ -3,7 +3,7 @@
set -evx
DOXYGEN_URL="ftp://ftp.stack.nl/pub/users/dimitri/doxygen-1.8.13.src.tar.gz"
DOXYGEN_URL="http://doxygen.nl/files/doxygen-1.8.15.src.tar.gz"
cd "${DEPS_DIR}"
if [[ ! -f "${DEPS_DIR}/doxygen/build/bin/doxygen" ]] ; then
......
root = true
[*]
indent_style = space
indent_size = 4
insert_final_newline = true
end_of_line = lf
trim_trailing_whitespace = true
......@@ -6,7 +6,7 @@
[subrepo]
remote = git@github.com:CLIUtils/CLI11.git
branch = master
commit = bd4dc911847d0cde7a6b41dfa626a85aab213baf
parent = 5c82607003abda391c299d089e4624664a41de7a
commit = 76d2cde6568c9c8870b728aa9bc64b70b29127fd
parent = ead793c351e37e34227121e50abdce709aeb81af
cmdver = 0.4.0
method = merge
language: cpp
sudo: false
dist: trusty
# Exclude ghpages,
......@@ -105,6 +104,20 @@ matrix:
conan upload "*" -c -r origin --all
fi
# GCC 4.8
- compiler: gcc
env:
- GCC_VER=4.8
addons:
apt:
packages:
- g++-4.8
install:
- export CC=gcc-4.8
- export CXX=g++-4.8
script:
- .ci/make_and_test.sh 11
# macOS and clang
- os: osx
compiler: clang
......
## Version 1.8: Sets and Flags (IN PROGRESS)
Set handling has been completely replaced by a new backend that works as a Validator. This provides a single interface instead of the 16 different functions in App. It also allows ordered collections to be used, custom functions for filtering, and better help and error messages. You can also use a collection of pairs (like `std::map`) to transform the match into an output. Also new are inverted flags, which can cancel or reduce the count of flags, and can also support general flag types. A new `add_option_fn` lets you more easily program CLI11 options with the types you choose. Vector options now support a custom separator. Apps can now be composed with unnamed subcommand support.
* New `CLI::IsMember` validator replaces set validation [#222]
* IsMember also supports container of pairs, transform allows modification of result [#228]
* Much more powerful flags with different values [#211], general types [#235]
* `add_option` now supports bool due to unified bool handling [#211]
* Support for composable unnamed subcommands [#216]
* Custom vector separator using `->delimiter(char)` [#209], [#221], [#240]
* Validators added for IP4 addresses and positive numbers [#210]
* Minimum required Boost for optional Optionals has been corrected to 1.61 [#226]
* Positionals can stop options from being parsed with `app.positionals_at_end()` [#223]
* Validators can be negated with `!` [#230], and now handle tname functions [#228]
* Better enum support and streaming helper [#233] and [#228]
* Cleanup for shadow warnings [#232]
> ### Converting from CLI11 1.7:
>
> * `app.add_set("--name", value, {"choice1", "choice2"})` should become `app.add_option("--name", value)->check(CLI::IsMember({"choice1", "choice2"}))`
> * The `_ignore_case` version of this can be replaced by adding `CLI::ignore_case` to the argument list in `IsMember`
> * The `_ignore_underscore` version of this can be replaced by adding `CLI::ignore_underscore` to the argument list in `IsMember`
> * The `_ignore_case_underscore` version of this can be replaced by adding both functions listed above to the argument list in `IsMember`
> * If you want an exact match to the original choice after one of the modifier functions matches, use `->transform` instead of `->check`
> * The `_mutable` versions of this can be replaced by passing a pointer or shared pointer into `IsMember`
> * An error with sets now produces a `ValidationError` instead of a `ConversionError`
[#209]: https://github.com/CLIUtils/CLI11/pull/209
[#210]: https://github.com/CLIUtils/CLI11/pull/210
[#211]: https://github.com/CLIUtils/CLI11/pull/211
[#216]: https://github.com/CLIUtils/CLI11/pull/216
[#221]: https://github.com/CLIUtils/CLI11/pull/221
[#222]: https://github.com/CLIUtils/CLI11/pull/222
[#223]: https://github.com/CLIUtils/CLI11/pull/223
[#226]: https://github.com/CLIUtils/CLI11/pull/226
[#228]: https://github.com/CLIUtils/CLI11/pull/228
[#230]: https://github.com/CLIUtils/CLI11/pull/230
[#232]: https://github.com/CLIUtils/CLI11/pull/232
[#233]: https://github.com/CLIUtils/CLI11/pull/233
[#235]: https://github.com/CLIUtils/CLI11/pull/235
[#240]: https://github.com/CLIUtils/CLI11/pull/240
## Version 1.7.1: Quick patch
This version provides a quick patch for a (correct) warning from GCC 8 for the windows options code.
* Fix for Windows style option parsing [#201]
* Improve `add_subcommand` when throwing an exception [#204]
* Better metadata for Conan package [#202]
[#201]: https://github.com/CLIUtils/CLI11/pull/201
[#202]: https://github.com/CLIUtils/CLI11/pull/202
[#204]: https://github.com/CLIUtils/CLI11/pull/204
## Version 1.7: Parse breakup
The parsing procedure now maps much more sensibly to complex, nested subcommand structures. Each phase of the parsing happens on all subcommands before moving on with the next phase of the parse. This allows several features, like required environment variables, to work properly even through subcommand boundaries.
Passing the same subcommand multiple times is better supported. Several new features were added as well, including Windows style option support, parsing strings directly, and ignoring underscores in names. Adding a set that you plan to change later must now be done with `add_mutable_set`.
* Support Windows style options with `->allow_windows_style_options`. [#187] On by default on Windows. [#190]
* Added `parse(string)` to split up and parse a command-line style string directly. [#186]
* Added `ignore_underscore` and related functions, to ignore underscores when matching names. [#185]
* The default INI Config will now add quotes to strings with spaces [#195]
* The default message now will mention the help-all flag also if present [#197]
* Added `->description` to set Option descriptions [#199]
* Mutating sets (introduced in Version 1.6) now have a clear add method, `add_mutable_set*`, since the set reference should not expire [#200]
* Subcommands now track how many times they were parsed in a parsing process. `count()` with no arguments will return the number of times a subcommand was encountered. [#179]
* Parsing is now done in phases: `shortcurcuits`, `ini`, `env`, `callbacks`, and `requirements`; all subcommands complete a phase before moving on. [#179]
* Calling parse multiple times is now officially supported without `clear` (automatic). [#179]
* Dropped the mostly undocumented `short_circuit` property, as help flag parsing is a bit more complex, and the default callback behavior of options now works properly. [#179]
* Use the standard `BUILD_TESTING` over `CLI11_TESTING` if defined (`CLI11_TESTING` may eventually be removed) [#183]
* Cleanup warnings [#191]
* Remove deprecated names: `set_footer`, `set_name`, `set_callback`, and `set_type_name`. Use without the `set_` instead. [#192]
> ### Converting from CLI11 1.6:
>
> * `->short_circuit()` is no longer needed, just remove it if you were using it - raising an exception will happen in the proper place now without it.
> * `->add_set*` becomes `->add_mutable_set*` if you were using the editable set feature
> * `footer`, `name`, `callback`, and `type_name` must be used instead of the `set_*` versions (deprecated previously).
[#179]: https://github.com/CLIUtils/CLI11/pull/179
[#183]: https://github.com/CLIUtils/CLI11/pull/183
[#185]: https://github.com/CLIUtils/CLI11/pull/185
[#186]: https://github.com/CLIUtils/CLI11/pull/186
[#187]: https://github.com/CLIUtils/CLI11/pull/187
[#190]: https://github.com/CLIUtils/CLI11/pull/190
[#191]: https://github.com/CLIUtils/CLI11/pull/191
[#192]: https://github.com/CLIUtils/CLI11/pull/192
[#197]: https://github.com/CLIUtils/CLI11/pull/197
[#195]: https://github.com/CLIUtils/CLI11/issues/195
[#199]: https://github.com/CLIUtils/CLI11/pull/199
[#200]: https://github.com/CLIUtils/CLI11/pull/200
## Version 1.6.2: Help-all
This version fixes some formatting bugs with help-all. It also adds fixes for several warnings, including an experimental optional error on Clang 7. Several smaller fixes.
......
......@@ -2,12 +2,12 @@ cmake_minimum_required(VERSION 3.4)
# Note: this is a header only library. If you have an older CMake than 3.4,
# just add the CLI11/include directory and that's all you need to do.
# Make sure users don't get warnings on a tested (3.4 to 3.12) version
# Make sure users don't get warnings on a tested (3.4 to 3.13) version
# of CMake. For most of the policies, the new version is better (hence the change).
if(${CMAKE_VERSION} VERSION_LESS 3.12)
if(${CMAKE_VERSION} VERSION_LESS 3.13)
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
else()
cmake_policy(VERSION 3.12)
cmake_policy(VERSION 3.13)
endif()
set(VERSION_REGEX "#define CLI11_VERSION[ \t]+\"(.+)\"")
......@@ -36,7 +36,7 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
if(MSVC)
add_definitions("/W4")
else()
add_definitions(-Wall -Wextra -pedantic)
add_definitions(-Wall -Wextra -pedantic -Wshadow)
endif()
if(CMAKE_VERSION VERSION_GREATER 3.6)
......@@ -96,12 +96,8 @@ endif()
# import Targets.cmake
# Add the version in a CMake readable way
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
CLI11ConfigVersion.cmake
VERSION ${CLI11_VERSION}
COMPATIBILITY AnyNewerVersion
)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/CLI11ConfigVersion.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/CLI11ConfigVersion.cmake" @ONLY)
# These installs only make sense for a local project
if(CUR_PROJ)
......@@ -156,6 +152,10 @@ endif()
cmake_dependent_option(CLI11_SINGLE_FILE_TESTS "Duplicate all the tests for a single file build" OFF "CLI11_SINGLE_FILE" OFF)
cmake_dependent_option(CLI11_TESTING "Build the tests and add them" ON "CUR_PROJ" OFF)
if(DEFINED BUILD_TESTING)
cmake_dependent_option(CLI11_TESTING "" ON "BUILD_TESTING" OFF)
message(STATUS "BUILD_TESTING is defined and it supersedes CLI11_TESTING. Has forced to ${CLI11_TESTING}")
endif()
if(CLI11_TESTING)
enable_testing()
add_subdirectory(tests)
......
CLI11 1.6 Copyright (c) 2017-2018 University of Cincinnati, developed by Henry
CLI11 1.7 Copyright (c) 2017-2019 University of Cincinnati, developed by Henry
Schreiner under NSF AWARD 1414736. All rights reserved.
Redistribution and use in source and binary forms of CLI11, with or without
......
This diff is collapsed.
# C/C++ with GCC
# Build your C/C++ project with GCC using make.
# Add steps that publish test results, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/apps/c-cpp/gcc
trigger:
- master
jobs:
- job: Linux
pool:
vmImage: 'ubuntu-16.04'
steps:
- template: .ci/azure-steps.yml
- job: macOS
pool:
vmImage: 'macOS-10.13'
steps:
- template: .ci/azure-steps.yml
- job: Windows
pool:
vmImage: 'vs2017-win2016'
steps:
- template: .ci/azure-steps.yml
......@@ -6,7 +6,10 @@
#
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
set(BUILD_SHARED_LIBS OFF)
# older version of google tests doesn't support MSYS so needs this flag to compile
if (MSYS)
set(gtest_disable_pthreads ON CACHE BOOL "" FORCE)
endif()
set(CMAKE_SUPPRESS_DEVELOPER_WARNINGS 1 CACHE BOOL "")
add_subdirectory("${CLI11_SOURCE_DIR}/extern/googletest" "${CLI11_BINARY_DIR}/extern/googletest" EXCLUDE_FROM_ALL)
......@@ -56,9 +59,11 @@ BUILD_GTEST
set_target_properties(gtest gtest_main gmock gmock_main
PROPERTIES FOLDER "Extern")
if(MSVC AND MSVC_VERSION GREATER_EQUAL 1900)
if(MSVC)
if (MSVC_VERSION GREATER_EQUAL 1900)
target_compile_definitions(gtest PUBLIC _SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING)
target_compile_definitions(gtest_main PUBLIC _SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING)
target_compile_definitions(gmock PUBLIC _SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING)
target_compile_definitions(gmock_main PUBLIC _SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING)
endif()
endif()
# Adapted from write_basic_package_version_file(... COMPATIBILITY AnyNewerVersion) output
# ARCH_INDEPENDENT is only present in cmake 3.14 and onwards
set(PACKAGE_VERSION "@VERSION_STRING@")
if(PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION)
set(PACKAGE_VERSION_COMPATIBLE FALSE)
else()
set(PACKAGE_VERSION_COMPATIBLE TRUE)
if(PACKAGE_FIND_VERSION STREQUAL PACKAGE_VERSION)
set(PACKAGE_VERSION_EXACT TRUE)
endif()
endif()
......@@ -10,14 +10,17 @@ def get_version():
except Exception:
return None
class HelloConan(ConanFile):
class CLI11Conan(ConanFile):
name = "CLI11"
version = get_version()
url = "https://github.com/CLIUtils/CLI11"
settings = "os", "compiler", "arch", "build_type"
license = "BSD 3 clause"
description = "Command Line Interface toolkit for C++11"
topics = ("cli", "c++11", "parser", "cli11")
url = "https://github.com/CLIUtils/CLI11"
homepage = "https://github.com/CLIUtils/CLI11"
author = "Henry Schreiner <hschrein@cern.ch>"
license = "BSD-3-Clause"
settings = "os", "compiler", "arch", "build_type"
exports_sources = "LICENSE", "README.md", "include/*", "extern/*", "cmake/*", "CMakeLists.txt", "tests/*"
def build(self): # this is not building a library, just tests
......
......@@ -63,11 +63,92 @@ set_property(TEST subcommands_all PROPERTY PASS_REGULAR_EXPRESSION
"Subcommand: start"
"Subcommand: stop")
add_cli_exe(subcom_partitioned subcom_partitioned.cpp)
add_test(NAME subcom_partitioned_none COMMAND subcom_partitioned)
set_property(TEST subcom_partitioned_none PROPERTY PASS_REGULAR_EXPRESSION
"This is a timer:"
"--file is required"
"Run with --help for more information.")
add_test(NAME subcom_partitioned_all COMMAND subcom_partitioned --file this --count --count -d 1.2)
set_property(TEST subcom_partitioned_all PROPERTY PASS_REGULAR_EXPRESSION
"This is a timer:"
"Working on file: this, direct count: 1, opt count: 1"
"Working on count: 2, direct count: 2, opt count: 2"
"Some value: 1.2")
# test shows that the help prints out for unnamed subcommands
add_test(NAME subcom_partitioned_help COMMAND subcom_partitioned --help)
set_property(TEST subcom_partitioned_help PROPERTY PASS_REGULAR_EXPRESSION
"-f,--file TEXT REQUIRED"
"-d,--double FLOAT")
add_cli_exe(option_groups option_groups.cpp)
add_test(NAME option_groups_missing COMMAND option_groups )
set_property(TEST option_groups_missing PROPERTY PASS_REGULAR_EXPRESSION
"Exactly 1 option from"
"is required")
add_test(NAME option_groups_extra COMMAND option_groups --csv --binary)
set_property(TEST option_groups_extra PROPERTY PASS_REGULAR_EXPRESSION
"and 2 were given")
add_test(NAME option_groups_extra2 COMMAND option_groups --csv --address "192.168.1.1" -o "test.out")
set_property(TEST option_groups_extra2 PROPERTY PASS_REGULAR_EXPRESSION
"at most 1")
add_cli_exe(positional_arity positional_arity.cpp)
add_test(NAME positional_arity1 COMMAND positional_arity one )
set_property(TEST positional_arity1 PROPERTY PASS_REGULAR_EXPRESSION
"File 1 = one")
add_test(NAME positional_arity2 COMMAND positional_arity one two )
set_property(TEST positional_arity2 PROPERTY PASS_REGULAR_EXPRESSION
"File 1 = one"
"File 2 = two")
add_test(NAME positional_arity3 COMMAND positional_arity 1 2 one)
set_property(TEST positional_arity3 PROPERTY PASS_REGULAR_EXPRESSION
"File 1 = one")
add_test(NAME positional_arity_fail COMMAND positional_arity 1 one two)
set_property(TEST positional_arity_fail PROPERTY PASS_REGULAR_EXPRESSION
"Could not convert")
add_cli_exe(positional_validation positional_validation.cpp)
add_test(NAME positional_validation1 COMMAND positional_validation one )
set_property(TEST positional_validation1 PROPERTY PASS_REGULAR_EXPRESSION
"File 1 = one")
add_test(NAME positional_validation2 COMMAND positional_validation one 1 2 two )
set_property(TEST positional_validation2 PROPERTY PASS_REGULAR_EXPRESSION
"File 1 = one"
"File 2 = two")
add_test(NAME positional_validation3 COMMAND positional_validation 1 2 one)
set_property(TEST positional_validation3 PROPERTY PASS_REGULAR_EXPRESSION
"File 1 = one")
add_test(NAME positional_validation4 COMMAND positional_validation 1 one two 2)
set_property(TEST positional_validation4 PROPERTY PASS_REGULAR_EXPRESSION
"File 1 = one"
"File 2 = two")
add_cli_exe(shapes shapes.cpp)
add_test(NAME shapes_all COMMAND shapes circle 4.4 circle 10.7 rectangle 4 4 circle 2.3 triangle 4.5 ++ rectangle 2.1 ++ circle 234.675)
set_property(TEST shapes_all PROPERTY PASS_REGULAR_EXPRESSION
"circle2"
"circle4"
"rectangle2 with edges [2.1,2.1]"
"triangel1 with sides [4.5]")
add_cli_exe(ranges ranges.cpp)
add_test(NAME ranges_range COMMAND ranges --range 1 2 3)
set_property(TEST ranges_range PROPERTY PASS_REGULAR_EXPRESSION
"[2:1:3]")
add_test(NAME ranges_minmax COMMAND ranges --min 2 --max 3)
set_property(TEST ranges_minmax PROPERTY PASS_REGULAR_EXPRESSION
"[2:1:3]")
add_test(NAME ranges_error COMMAND ranges --min 2 --max 3 --step 1 --range 1 2 3)
set_property(TEST ranges_error PROPERTY PASS_REGULAR_EXPRESSION
"Exactly 1 option from")
add_cli_exe(validators validators.cpp)
add_test(NAME validators_help COMMAND validators --help)
set_property(TEST validators_help PROPERTY PASS_REGULAR_EXPRESSION
" -f,--file FILE File name"
" -v,--value INT in [3 - 6] Value in range")
" -f,--file TEXT:FILE[\\r\\n\\t ]+File name"
" -v,--value INT:INT in [3 - 6][\\r\\n\\t ]+Value in range")
add_test(NAME validators_file COMMAND validators --file nonex.xxx)
set_property(TEST validators_file PROPERTY PASS_REGULAR_EXPRESSION
"--file: File does not exist: nonex.xxx"
......@@ -112,7 +193,12 @@ add_cli_exe(enum enum.cpp)
add_test(NAME enum_pass COMMAND enum -l 1)
add_test(NAME enum_fail COMMAND enum -l 4)
set_property(TEST enum_fail PROPERTY PASS_REGULAR_EXPRESSION
"Could not convert: --level = 4")
"--level: Check 4 value in {" "FAILED")
add_cli_exe(digit_args digit_args.cpp)
add_test(NAME digit_args COMMAND digit_args -h)
set_property(TEST digit_args PROPERTY PASS_REGULAR_EXPRESSION
"-3{3}")
add_cli_exe(modhelp modhelp.cpp)
add_test(NAME modhelp COMMAND modhelp -a test -h)
......
#include <CLI/CLI.hpp>
#include <iostream>
int main(int argc, char **argv) {
CLI::App app;
int val;
// add a set of flags with default values associate with them
app.add_flag("-1{1},-2{2},-3{3},-4{4},-5{5},-6{6}, -7{7}, -8{8}, -9{9}", val, "compression level");
CLI11_PARSE(app, argc, argv);
std::cout << "value = " << val << std::endl;
return 0;
}
#include <CLI/CLI.hpp>
#include <sstream>
enum class Level : int { High, Medium, Low };
std::istream &operator>>(std::istream &in, Level &level) {
int i;
in >> i;
level = static_cast<Level>(i);
return in;
}
std::ostream &operator<<(std::ostream &in, const Level &level) { return in << static_cast<int>(level); }
int main(int argc, char **argv) {
CLI::App app;
Level level;
app.add_set("-l,--level", level, {Level::High, Level::Medium, Level::Low}, "Level settings")
->type_name("enum/Level in {High=0, Medium=1, Low=2}");
// specify string->value mappings
std::vector<std::pair<std::string, Level>> map{
{"high", Level::High}, {"medium", Level::Medium}, {"low", Level::Low}};
// checked Transform does the translation and checks the results are either in one of the strings or one of the
// translations already
app.add_option("-l,--level", level, "Level settings")
->required()
->transform(CLI::CheckedTransformer(map, CLI::ignore_case));
CLI11_PARSE(app, argc, argv);
// CLI11's built in enum streaming can be used outside CLI11 like this:
using namespace CLI::enums;
std::cout << "Enum received: " << level << std::endl;
return 0;
}
#include "CLI/CLI.hpp"
int main(int argc, char **argv) {
CLI::App app("data output specification");
app.set_help_all_flag("--help-all", "Expand all help");
auto format = app.add_option_group("output_format", "formatting type for output");
auto target = app.add_option_group("output target", "target location for the output");
bool csv = false;
bool human = false;
bool binary = false;
format->add_flag("--csv", csv, "specify the output in csv format");
format->add_flag("--human", human, "specify the output in human readable text format");
format->add_flag("--binary", binary, "specify the output in binary format");
// require one of the options to be selected
format->require_option(1);
std::string fileLoc;
std::string networkAddress;
target->add_option("-o,--file", fileLoc, "specify the file location of the output");
target->add_option("--address", networkAddress, "specify a network address to send the file");
// require at most one of the target options
target->require_option(0, 1);
CLI11_PARSE(app, argc, argv);
std::string format_type = (csv) ? std::string("CSV") : ((human) ? "human readable" : "binary");
std::cout << "Selected " << format_type << "format" << std::endl;
if(fileLoc.empty()) {
std::cout << " sent to file " << fileLoc << std::endl;
} else if(networkAddress.empty()) {
std::cout << " sent over network to " << networkAddress << std::endl;
} else {
std::cout << " sent to std::cout" << std::endl;
}
return 0;
}
#include "CLI/CLI.hpp"
int main(int argc, char **argv) {
CLI::App app("test for positional arity");
auto numbers = app.add_option_group("numbers", "specify key numbers");
auto files = app.add_option_group("files", "specify files");
int num1 = -1, num2 = -1;
numbers->add_option("num1", num1, "first number");
numbers->add_option("num2", num2, "second number");
std::string file1, file2;
files->add_option("file1", file1, "first file")->required();
files->add_option("file2", file2, "second file");
// set a pre parse callback that turns the numbers group on or off depending on the number of arguments
app.preparse_callback([numbers](size_t arity) {
if(arity <= 2) {
numbers->disabled();
} else {
numbers->disabled(false);
}
});
CLI11_PARSE(app, argc, argv);
if(num1 != -1)
std::cout << "Num1 = " << num1 << '\n';
if(num2 != -1)
std::cout << "Num2 = " << num2 << '\n';
std::cout << "File 1 = " << file1 << '\n';
if(!file2.empty()) {
std::cout << "File 2 = " << file2 << '\n';
}
return 0;
}
#include "CLI/CLI.hpp"
int main(int argc, char **argv) {
CLI::App app("test for positional validation");
int num1 = -1, num2 = -1;
app.add_option("num1", num1, "first number")->check(CLI::Number);
app.add_option("num2", num2, "second number")->check(CLI::Number);
std::string file1, file2;
app.add_option("file1", file1, "first file")->required();
app.add_option("file2", file2, "second file");
app.validate_positionals();
CLI11_PARSE(app, argc, argv);
if(num1 != -1)
std::cout << "Num1 = " << num1 << '\n';
if(num2 != -1)
std::cout << "Num2 = " << num2 << '\n';
std::cout << "File 1 = " << file1 << '\n';
if(!file2.empty()) {
std::cout << "File 2 = " << file2 << '\n';
}
return 0;
}
#include "CLI/CLI.hpp"
int main(int argc, char **argv) {
CLI::App app{"App to demonstrate exclusionary option groups."};
std::vector<int> range;
app.add_option("--range,-R", range, "A range")->expected(-2);
auto ogroup = app.add_option_group("min_max_step", "set the min max and step");
int min, max, step = 1;
ogroup->add_option("--min,-m", min, "The minimum")->required();
ogroup->add_option("--max,-M", max, "The maximum")->required();
ogroup->add_option("--step,-s", step, "The step", true);
app.require_option(1);
CLI11_PARSE(app, argc, argv);
if(!range.empty()) {
if(range.size() == 2) {
min = range[0];
max = range[1];
}
if(range.size() >= 3) {
step = range[0];
min = range[1];
max = range[2];
}
}
std::cout << "range is [" << min << ':' << step << ':' << max << "]\n";
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment