diff --git a/packages/CLI11/.appveyor.yml b/packages/CLI11/.appveyor.yml new file mode 100644 index 0000000000000000000000000000000000000000..6d4f5b5e63fed94324d5e54520e07a672ac2fc60 --- /dev/null +++ b/packages/CLI11/.appveyor.yml @@ -0,0 +1,28 @@ +branches: + except: + - gh-pages + +install: + - set PATH=C:\Python36;%PATH% + - cmake --version + - pip install conan + - conan user + - conan --version + +build_script: + - mkdir build + - cd build + - cmake .. -DCLI_SINGLE_FILE_TESTS=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_GENERATOR="Visual Studio 14 2015" + - cmake --build . + - cd .. + - conan create . CLIUtils/CLI11 + +test_script: + - ctest --output-on-failure -C Debug + +notifications: + - provider: Webhook + url: https://webhooks.gitter.im/e/0185e91c5d989a476d7b + on_build_success: false + on_build_failure: true + on_build_status_changed: true diff --git a/packages/CLI11/.ci/build_cmake.sh b/packages/CLI11/.ci/build_cmake.sh new file mode 100644 index 0000000000000000000000000000000000000000..5b2d69bb61fc49989eecb993da8ffc4c55acc4af --- /dev/null +++ b/packages/CLI11/.ci/build_cmake.sh @@ -0,0 +1,17 @@ +CMAKE_VERSION=3.9.6 +CMAKE_MVERSION=${CMAKE_VERSION%.*} +# Non Bash version: +# echo CMAKE_MVERSION=`$var | awk -F"." '{ print $1"."$2 }'` + +if [ "$TRAVIS_OS_NAME" = "linux" ] ; then CMAKE_URL="https://cmake.org/files/v${CMAKE_MVERSION}/cmake-${CMAKE_VERSION}-Linux-x86_64.tar.gz" ; fi +if [ "$TRAVIS_OS_NAME" = "osx" ] ; then CMAKE_URL="https://cmake.org/files/v$CMAKE_MVERSION/cmake-$CMAKE_VERSION-Darwin-x86_64.tar.gz" ; fi +cd "${DEPS_DIR}" + +if [[ ! -f "${DEPS_DIR}/cmake/bin/cmake" ]] ; then + echo "Downloading CMake $CMAKE_VERSION" + mkdir -p cmake + travis_retry wget --no-check-certificate --quiet -O - "${CMAKE_URL}" | tar --strip-components=1 -xz -C cmake +fi + +export PATH="${DEPS_DIR}/cmake/bin:${PATH}" +cd "${TRAVIS_BUILD_DIR}" diff --git a/packages/CLI11/.ci/build_docs.sh b/packages/CLI11/.ci/build_docs.sh new file mode 100755 index 0000000000000000000000000000000000000000..b8fab375429ae4ca692c6497866f8fb9cd8ea6b4 --- /dev/null +++ b/packages/CLI11/.ci/build_docs.sh @@ -0,0 +1,106 @@ +#!/bin/sh +################################################################################ +# Title : generateDocumentationAndDeploy.sh +# Date created : 2016/02/22 +# Notes : +__AUTHOR__="Jeroen de Bruijn" +# Preconditions: +# - Packages doxygen doxygen-doc doxygen-latex doxygen-gui graphviz +# must be installed. +# - Doxygen configuration file must have the destination directory empty and +# source code directory with a $(TRAVIS_BUILD_DIR) prefix. +# - An gh-pages branch should already exist. See below for mor info on hoe to +# create a gh-pages branch. +# +# Required global variables: +# - TRAVIS_BUILD_NUMBER : The number of the current build. +# - TRAVIS_COMMIT : The commit that the current build is testing. +# - DOXYFILE : The Doxygen configuration file. +# - TRAVIS_REPO_SLUG : The username / reponame for the repository. +# - GH_REPO_TOKEN : Secure token to the github repository. +# +# For information on how to encrypt variables for Travis CI please go to +# https://docs.travis-ci.com/user/environment-variables/#Encrypted-Variables +# or https://gist.github.com/vidavidorra/7ed6166a46c537d3cbd2 +# For information on how to create a clean gh-pages branch from the master +# branch, please go to https://gist.github.com/vidavidorra/846a2fc7dd51f4fe56a0 +# +# This script will generate Doxygen documentation and push the documentation to +# the gh-pages branch of a repository specified by GH_REPO_REF. +# Before this script is used there should already be a gh-pages branch in the +# repository. +# +################################################################################ + +################################################################################ +##### Setup this script and get the current gh-pages branch. ##### +echo 'Setting up the script...' +# Exit with nonzero exit code if anything fails +set -e + +GH_REPO_ORG=`echo $TRAVIS_REPO_SLUG | cut -d "/" -f 1` +GH_REPO_NAME=`echo $TRAVIS_REPO_SLUG | cut -d "/" -f 2` +GH_REPO_REF="github.com/$GH_REPO_ORG/$GH_REPO_NAME.git" + +# Create a clean working directory for this script. +# Get the current gh-pages branch +cd docs +git clone -b gh-pages https://git@$GH_REPO_REF html +cd html + +##### Configure git. +# Set the push default to simple i.e. push only the current branch. +git config --global push.default simple +# Pretend to be an user called Travis CI. +git config user.name "Travis CI" +git config user.email "travis@travis-ci.org" + +# Remove everything currently in the gh-pages branch. +# GitHub is smart enough to know which files have changed and which files have +# stayed the same and will only update the changed files. So the gh-pages branch +# can be safely cleaned, and it is sure that everything pushed later is the new +# documentation. +rm -rf * + +# Need to create a .nojekyll file to allow filenames starting with an underscore +# to be seen on the gh-pages site. Therefore creating an empty .nojekyll file. +# Presumably this is only needed when the SHORT_NAMES option in Doxygen is set +# to NO, which it is by default. So creating the file just in case. +echo "" > .nojekyll + +################################################################################ +##### Generate the Doxygen code documentation and log the output. ##### +echo 'Generating Doxygen code documentation...' +# Redirect both stderr and stdout to the log file AND the console. +cd .. +doxygen $DOXYFILE 2>&1 | tee doxygen.log + +################################################################################ +##### Upload the documentation to the gh-pages branch of the repository. ##### +# Only upload if Doxygen successfully created the documentation. +# Check this by verifying that the html directory and the file html/index.html +# both exist. This is a good indication that Doxygen did it's work. +if [ -d "html" ] && [ -f "html/index.html" ]; then + + cd html + echo 'Uploading documentation to the gh-pages branch...' + # Add everything in this directory (the Doxygen code documentation) to the + # gh-pages branch. + # GitHub is smart enough to know which files have changed and which files have + # stayed the same and will only update the changed files. + git add --all + + # Commit the added files with a title and description containing the Travis CI + # build number and the GitHub commit reference that issued this build. + git commit -m "Deploy code docs to GitHub Pages Travis build: ${TRAVIS_BUILD_NUMBER}" -m "Commit: ${TRAVIS_COMMIT}" + + # Force push to the remote gh-pages branch. + # The ouput is redirected to /dev/null to hide any sensitive credential data + # that might otherwise be exposed. + git push --force "https://${GH_REPO_TOKEN}@${GH_REPO_REF}" > /dev/null 2>&1 +else + echo '' >&2 + echo 'Warning: No documentation (html) files have been found!' >&2 + echo 'Warning: Not going to push the documentation to GitHub!' >&2 + exit 1 +fi diff --git a/packages/CLI11/.ci/build_doxygen.sh b/packages/CLI11/.ci/build_doxygen.sh new file mode 100644 index 0000000000000000000000000000000000000000..5087f2be12e3d5c739ccec611fa59bac1de0732e --- /dev/null +++ b/packages/CLI11/.ci/build_doxygen.sh @@ -0,0 +1,17 @@ +DOXYGEN_URL="ftp://ftp.stack.nl/pub/users/dimitri/doxygen-1.8.13.src.tar.gz" +cd "${DEPS_DIR}" + +if [[ ! -f "${DEPS_DIR}/doxygen/build/bin/doxygen" ]] ; then + echo "Downloading Doxygen" + mkdir -p doxygen + travis_retry wget --no-check-certificate --quiet -O - "${DOXYGEN_URL}" | tar --strip-components=1 -xz -C doxygen + cd doxygen + mkdir -p build + cd build + cmake .. + make -j2 +fi + +export PATH="${DEPS_DIR}/doxygen/build/bin:${PATH}" + +cd "${TRAVIS_BUILD_DIR}" diff --git a/packages/CLI11/.ci/build_lcov.sh b/packages/CLI11/.ci/build_lcov.sh new file mode 100644 index 0000000000000000000000000000000000000000..3b89dd33c023ef192d82a326c522888a5a3acab0 --- /dev/null +++ b/packages/CLI11/.ci/build_lcov.sh @@ -0,0 +1,11 @@ +LCOV_URL="http://ftp.de.debian.org/debian/pool/main/l/lcov/lcov_1.13.orig.tar.gz" +cd "${DEPS_DIR}" + +if [[ ! -f "${DEPS_DIR}/lcov/bin/lcov" ]] ; then + echo "Downloading lcov" + mkdir -p lcov + travis_retry wget --no-check-certificate --quiet -O - "${LCOV_URL}" | tar --strip-components=1 -xz -C lcov +fi + +export PATH="${DEPS_DIR}/lcov/bin:${PATH}" +cd "${TRAVIS_BUILD_DIR}" diff --git a/packages/CLI11/.ci/check_tidy.sh b/packages/CLI11/.ci/check_tidy.sh new file mode 100755 index 0000000000000000000000000000000000000000..55189d9e4624c340c15095cb5068047610b113b7 --- /dev/null +++ b/packages/CLI11/.ci/check_tidy.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env sh +set -evx + +mkdir build-tidy || true +cd build-tidy +CXX_FLAGS="-Werror -Wall -Wextra -pedantic -std=c++11" cmake .. -DCLANG_TIDY_FIX=ON +cmake --build . + +git diff --exit-code --color + +set +evx diff --git a/packages/CLI11/.ci/prepare_altern.sh b/packages/CLI11/.ci/prepare_altern.sh new file mode 100644 index 0000000000000000000000000000000000000000..e384b00347fff628d8ca88621d868d79d7fe02cf --- /dev/null +++ b/packages/CLI11/.ci/prepare_altern.sh @@ -0,0 +1,18 @@ +cd "${DEPS_DIR}" +mkdir -p extrabin +cd extrabin + +if [ "$CXX" = "g++" ] ; then + ln -s `which gcc-$COMPILER` gcc + ln -s `which g++-$COMPILER` g++ + ln -s `which gcov-$COMPILER` gcov +else + ln -s `which clang-$COMPILER` clang + ln -s `which clang++-$COMPILER` clang++ + ln -s `which clang-format-$COMPILER` clang-format + ln -s `which clang-tidy-$COMPILER` clang-tidy +fi + +export PATH="${DEPS_DIR}/extrabin":$PATH + +cd "${TRAVIS_BUILD_DIR}" diff --git a/packages/CLI11/.ci/run_codecov.sh b/packages/CLI11/.ci/run_codecov.sh new file mode 100755 index 0000000000000000000000000000000000000000..cd7219a8ceb31d8bca77e7ab8a797e45a5798cb0 --- /dev/null +++ b/packages/CLI11/.ci/run_codecov.sh @@ -0,0 +1,14 @@ +set -evx + +cd ${TRAVIS_BUILD_DIR} +mkdir -p build +cd build +cmake .. -DCLI_SINGLE_FILE_TESTS=OFF -DCLI_EXAMPLES=OFF -DCMAKE_BUILD_TYPE=Coverage +cmake --build . -- -j2 +cmake --build . --target CLI_coverage + +lcov --directory . --capture --output-file coverage.info # capture coverage info +lcov --remove coverage.info '*/tests/*' '*/examples/*' '*gtest*' '*gmock*' '/usr/*' --output-file coverage.info # filter out system +lcov --list coverage.info #debug info +# Uploading report to CodeCov +bash <(curl -s https://codecov.io/bash) || echo "Codecov did not collect coverage reports" diff --git a/packages/CLI11/.ci/travis.sh b/packages/CLI11/.ci/travis.sh new file mode 100755 index 0000000000000000000000000000000000000000..49cc2f8ea8e2abfdcd4b214e2ea1bc328e115273 --- /dev/null +++ b/packages/CLI11/.ci/travis.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env sh +set -evx + +mkdir build || true +cd build +cmake .. -DCLI_CXX_STD=11 -DCLI_SINGLE_FILE_TESTS=ON -DCMAKE_BUILD_TYPE=Debug +cmake --build . -- -j2 +ctest --output-on-failure +if [ -n "$CLI_CXX_STD" ] && [ "$CLI_CXX_STD" -ge "14" ] ; then + cmake .. -DCLI_CXX_STD=14 -DCLI_SINGLE_FILE_TESTS=ON -DCMAKE_BUILD_TYPE=Debug + cmake --build . -- -j2 + ctest --output-on-failure +fi +if [ -n "$CLI_CXX_STD" ] && [ "$CLI_CXX_STD" -ge "17" ] ; then + cmake .. -DCLI_CXX_STD=17 -DCLI_SINGLE_FILE_TESTS=ON -DCMAKE_BUILD_TYPE=Debug + cmake --build . -- -j2 + ctest --output-on-failure +fi + +set +evx diff --git a/packages/CLI11/.clang-format b/packages/CLI11/.clang-format new file mode 100644 index 0000000000000000000000000000000000000000..666a2ba79df8a4ec89c7a2a8c3e59ed7327050e8 --- /dev/null +++ b/packages/CLI11/.clang-format @@ -0,0 +1,86 @@ +Language: Cpp +BasedOnStyle: LLVM +# AccessModifierOffset: -2 +# AlignAfterOpenBracket: Align +# AlignConsecutiveAssignments: false +# AlignConsecutiveDeclarations: false +# AlignEscapedNewlinesLeft: false +# AlignOperands: true +# AlignTrailingComments: true +# AllowAllParametersOfDeclarationOnNextLine: true +# AllowShortBlocksOnASingleLine: false +# AllowShortCaseLabelsOnASingleLine: false +# AllowShortFunctionsOnASingleLine: All +# AllowShortIfStatementsOnASingleLine: false +# AllowShortLoopsOnASingleLine: false +# AlwaysBreakAfterDefinitionReturnType: None +# AlwaysBreakAfterReturnType: None +# AlwaysBreakBeforeMultilineStrings: false +# AlwaysBreakTemplateDeclarations: false +BinPackArguments: false +BinPackParameters: false +# BraceWrapping: +# AfterClass: false +# AfterControlStatement: false +# AfterEnum: false +# AfterFunction: false +# AfterNamespace: false +# AfterObjCDeclaration: false +# AfterStruct: false +# AfterUnion: false +# BeforeCatch: false +# BeforeElse: false +# IndentBraces: false +# BreakBeforeBinaryOperators: None +# BreakBeforeBraces: Attach +# BreakBeforeTernaryOperators: true +# BreakConstructorInitializersBeforeComma: false +# BreakAfterJavaFieldAnnotations: false +# BreakStringLiterals: true +ColumnLimit: 120 +# CommentPragmas: '^ IWYU pragma:' +# ConstructorInitializerAllOnOneLineOrOnePerLine: false +# ConstructorInitializerIndentWidth: 4 +# ContinuationIndentWidth: 4 +# Cpp11BracedListStyle: true +# DerivePointerAlignment: false +# DisableFormat: false +# ExperimentalAutoDetectBinPacking: false +# ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] +# IncludeIsMainRegex: '$' +# IndentCaseLabels: false +IndentWidth: 4 +# IndentWrappedFunctionNames: false +# JavaScriptQuotes: Leave +# JavaScriptWrapImports: true +# KeepEmptyLinesAtTheStartOfBlocks: true +# MacroBlockBegin: '' +# MacroBlockEnd: '' +# MaxEmptyLinesToKeep: 1 +# NamespaceIndentation: None +# ObjCBlockIndentWidth: 2 +# ObjCSpaceAfterProperty: false +# ObjCSpaceBeforeProtocolList: true +# PenaltyBreakBeforeFirstCallParameter: 19 +# PenaltyBreakComment: 300 +# PenaltyBreakFirstLessLess: 120 +# PenaltyBreakString: 1000 +# PenaltyExcessCharacter: 1000000 +# PenaltyReturnTypeOnItsOwnLine: 60 +# PointerAlignment: Right +# ReflowComments: true +SortIncludes: false +# SpaceAfterCStyleCast: false +# SpaceAfterTemplateKeyword: true +# SpaceBeforeAssignmentOperators: true +SpaceBeforeParens: Never +# SpaceInEmptyParentheses: false +# SpacesBeforeTrailingComments: 1 +# SpacesInAngles: false +# SpacesInContainerLiterals: true +# SpacesInCStyleCastParentheses: false +# SpacesInParentheses: false +# SpacesInSquareBrackets: false +Standard: Cpp11 +TabWidth: 4 +UseTab: Never diff --git a/packages/CLI11/.clang-tidy b/packages/CLI11/.clang-tidy new file mode 100644 index 0000000000000000000000000000000000000000..dbf7d077ff9b9a2e5b2df7e714e56d7973096083 --- /dev/null +++ b/packages/CLI11/.clang-tidy @@ -0,0 +1,8 @@ +#Checks: '*,-clang-analyzer-alpha.*' +#Checks: '-*,google-readability-casting,llvm-namespace-comment,performance-unnecessary-value-param,llvm-include-order,misc-throw-by-value-catch-by-reference,readability-container-size-empty,google-runtime-references,modernize*' +Checks: '-*,llvm-namespace-comment,readability-container-size-empty,misc-throw-by-value-catch-by-reference,modernize*,google-readability-casting' +HeaderFilterRegex: '.*hpp' +CheckOptions: +- key: readability-braces-around-statements.ShortStatementLines + value: '1' + diff --git a/packages/CLI11/.codecov.yml b/packages/CLI11/.codecov.yml new file mode 100644 index 0000000000000000000000000000000000000000..a53035820b6c1fa93a6f9c3cf9599a41db29ee1b --- /dev/null +++ b/packages/CLI11/.codecov.yml @@ -0,0 +1,3 @@ + +ignore: + - "tests" diff --git a/packages/CLI11/.github/CONTRIBUTING.md b/packages/CLI11/.github/CONTRIBUTING.md new file mode 100644 index 0000000000000000000000000000000000000000..8db2a87a2294aabfb054ba8a6c53172d324b384f --- /dev/null +++ b/packages/CLI11/.github/CONTRIBUTING.md @@ -0,0 +1,9 @@ +# A few notes on contributions + +If you want to add code, please make sure it passes the clang-format style (I am using LLVM 4.0): + +```bash +git ls-files -- '.cpp' '.hpp' | xargs clang-format -i -style=file +``` + +It is also a good idea to check this with `clang-tidy`; automatic fixes can be made using `-DCLANG_TIDY_FIX-ON` (resets to `OFF` when rerunning CMake). diff --git a/packages/CLI11/.gitignore b/packages/CLI11/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..66ead1a57dcdaa5361a5d8711abca84af3e3070b --- /dev/null +++ b/packages/CLI11/.gitignore @@ -0,0 +1,7 @@ +a.out* +*.swp +/*build* +/test_package/build +/Makefile +/CMakeFiles/* +/cmake_install.cmake diff --git a/packages/CLI11/.gitrepo b/packages/CLI11/.gitrepo new file mode 100644 index 0000000000000000000000000000000000000000..11c78bd365d1a7fbb3db8acc8765f341c4d4a563 --- /dev/null +++ b/packages/CLI11/.gitrepo @@ -0,0 +1,11 @@ +; DO NOT EDIT (unless you know what you are doing) +; +; This subdirectory is a git "subrepo", and this file is maintained by the +; git-subrepo command. See https://github.com/git-commands/git-subrepo#readme +; +[subrepo] + remote = git@github.com:CLIUtils/CLI11.git + branch = master + commit = b4b7d991f69add2e4fb007d1df4c14a088127d9b + parent = 8546076c470f8af8014418e169819302cd7d1f66 + cmdver = 0.3.1 diff --git a/packages/CLI11/.travis.yml b/packages/CLI11/.travis.yml new file mode 100644 index 0000000000000000000000000000000000000000..c02c44b065513bf4b5b9ff235f2870b1f7e938d8 --- /dev/null +++ b/packages/CLI11/.travis.yml @@ -0,0 +1,136 @@ +language: cpp +sudo: false +dist: trusty +branches: + exclude: + - gh-pages +cache: + directories: + - "${TRAVIS_BUILD_DIR}/deps/cmake" + - "${TRAVIS_BUILD_DIR}/deps/doxygen" +matrix: + include: + - compiler: clang + addons: + apt: + sources: + - ubuntu-toolchain-r-test + - llvm-toolchain-trusty-5.0 + packages: + - clang++-5.0 + env: + - COMPILER=5.0 + - CLI_CXX_STD=14 + - compiler: clang + addons: + apt: + packages: + - clang-3.9 + - clang-format-3.9 + - clang-tidy-3.9 + env: + - COMPILER=3.9 + - CLI_CXX_STD=14 + script: + - cd "${TRAVIS_BUILD_DIR}" + - scripts/check_style.sh + - ".ci/check_tidy.sh" + - compiler: clang + addons: + apt: + packages: + - clang-3.5 + env: + - COMPILER=3.5 + - DEPLOY_MAT=yes + - DOXYFILE=$TRAVIS_BUILD_DIR/docs/Doxyfile + after_success: + - | + if [ "${TRAVIS_BRANCH}" == "master" ] && [ "${TRAVIS_PULL_REQUEST}" == "false" ] + then + echo "Updating docs" && cd $TRAVIS_BUILD_DIR && .ci/build_docs.sh + fi + - compiler: gcc + addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-6 + - curl + - lcov + env: + - COMPILER=6 + - CLI_CXX_STD=14 + before_install: + - DEPS_DIR="${TRAVIS_BUILD_DIR}/deps" + - cd $TRAVIS_BUILD_DIR + - ". .ci/build_lcov.sh" + - ".ci/run_codecov.sh" + - compiler: gcc + addons: + apt: + packages: + - g++-4.7 + env: + - COMPILER=4.7 + before_install: + - python -m pip install --user conan + - conan user + after_success: + - conan create . CLIUtils/stable + - | + if [ "${TRAVIS_TAG}" ] + then + conan remote add origin https://api.bintray.com/conan/cliutils/CLI11 + conan user -p ${BINFROG_API_KEY} -r origin henryiii + conan upload "*" -c -r origin --all + fi + - os: osx + compiler: clang + before_install: + - brew update + - echo 'brew "python"' > Brewfile + - echo 'brew "conan"' >> Brewfile + - brew bundle + - python -m ensurepip --user + - conan user + after_success: + - conan create . CLIUtils/CLI11 +install: +- python -c 'import sys; print(sys.version_info[:])' +- DEPS_DIR="${TRAVIS_BUILD_DIR}/deps" +- if [ "$TRAVIS_OS_NAME" = "linux" ]; then cd $TRAVIS_BUILD_DIR && . .ci/prepare_altern.sh + ; fi +- if [ "$TRAVIS_OS_NAME" = "linux" ] ; then cd $TRAVIS_BUILD_DIR && . .ci/build_cmake.sh + ; fi +- if [ "$TRAVIS_OS_NAME" = "linux" ] ; then cd $TRAVIS_BUILD_DIR && . .ci/build_doxygen.sh + ; fi +- cd "${DEPS_DIR}" +- if [ "$(python -c 'import sys; print(sys.version_info[0])')" = "2" ] ; then python + -m pip install --user pathlib ; fi +- cmake --version +script: +- cd "${TRAVIS_BUILD_DIR}" +- ".ci/travis.sh" +deploy: + provider: releases + api_key: + secure: L1svZ5J+RiR67dj1fNk/XiZRvYfGJC4c5/dKSvDH+yuKSzZ6ODaTiVmYF8NtMJ7/3AQenEa0OuRBVQ0YpngFz3ugIcRsGCDUHtCMK/Bti0+6ZFdICbqcv6W3BlRIM8s7EOBPhjfbCV+ae7xep9B24HmwBPKukMFjDIj4nwBsmwCHZK9iNFtfaW2J2cr2TJo7QPY01J0W1k/boaj91KzHf9UuhEH8KYqp7szv+6kV00W8bRBtugw419dIm25eXFXgXDT9s/OA7qXV7o5FXWWpkyJ5AINVbY9DerkYag5TStrdOyKk+S1FexRG6TMG4L4Jyu/QxQGhMdu0m1yRCLvIekGtWLDnjNrI2SZrd5HbKprQ0O8j1770Is4q5blVPqAZ6O9jVMJRtVEaYbsJwItz1BJWkPT4S9GFbDL1dq2Z5jR2f5gd/cz2yYH56b47iYHWtzSqEfVhsXiN+atD+tWyQFA4Q/av0bGHwJ6LX0A1q0OCHruUMoxcw1QKfYtV1bkf/folL4Z4Hx3CL+NB0Lkqs8LFsQHxODP4a26I5DS/kaDHofotho8wsWlKFDtonZa+CExORGFFMPnGRz2qX5tMgGoo84wcqrprfoQv2llqeUr3gISPl2qxrljAhj3/Dcl7iI7k0Er7Ji8ENpgjSec4aqnBx8Ke2yaDEmBvwbouFCM= + skip_cleanup: true + file: build/include/CLI11.hpp + on: + repo: CLIUtils/CLI11 + tags: true + condition: "$DEPLOY_MAT = yes" +notifications: + webhooks: + urls: + - https://webhooks.gitter.im/e/bbdb3befce4c00448d24 + on_success: change + on_failure: always + on_start: never +env: + global: + - secure: cY0OI609iTAxLRYuYQnNMi+H6n0dBwioTAoFXGGRTnngw2V9om3UmY5eUu4HQEQsQZovHdYpNhlSgRmdwQ4UqSp3FGyrwobf0kzacV4bVnMDeXDmHt8RzE5wP/LwDd8elNF6RRYjElY99f0k0FyXVd0fIvuVkGKQECNLOtEk0jQo+4YTh7dhuCxRhBYgTbNiRL6UJynfrcK0YN+DQ+8CJNupu2VxgaEpCSngTfvDHLcddcrXwpvn3MPc3FsDUbtN389ZCIe41qqIL0ATv46DQaTw4FOevyVfRyrBOznONoGCVeAYKL6VBdrk01Fh6aytF5zgI3hKaKobgEn+QFfzR6l68c6APvqA0Qv39iLjuh6KbdIV2YsqXfyt6FBgqP2xZuNEZW1jZ8LxUOLl2I40UEh87nFutvnSbfIzN+FcLrajm2H2jV2kZGNKAMx+4qxkZuXSre4JPkENfJm2WNFAKlqPt4ZSEQarkDYzZPcEr2I9fbGjQYVJICoN4LikCv9K5z7ujpTxCTNbVpQWZcEOT6QQBc6Vml/N/NKAIl9o2OeTLiXCmT31+KQMeO492KYNQ6VmkeqrVhGExOUcJdNyDJV9C+3mSekb3Sq78SneYRKDechkWbMl0ol07wGTdBwQQwgaorjRyn07x1rDxpPr3z19/+eubnpPUW4UQ5MYsjs= + - secure: G6H5HA9pPUgsd96A+uvTxbLjR1rcT9NtxsknIkFDfzGDpffn6wVX+kCIQLf9zFDnQnsfYA/4piiuoBN5U5C7HQrh9UCvBVptXjWviea0Y7CRbMJZpw2rPvXWQtrFNzYkaV7kdJ5B0Mmvh6rcH/I8gKFrkdjF7i7sfzWdFWRU5QXfxXOk2n+xCXX6uFemxHH9850XEjVtnU7YYUebQFaoTYLLy05nlt9JaEF84wfJljY/SJX7I9gpNLtizE9MpJylnrwUeL66OqFievmjL3/bWpPUBjUF0WdtXYlVDja7O582FQDs94ofgqeGieGIMQ0VuovpbQOJSdjs5XHZwu2ce6HZxtOhJJqw6xEwbq43ZdofAlJ5GUEOgrr+j25zIDkdzOhliDKJtw5ysmmTUKEcZ36iWbCE0YP/IC42yOV9oOP6UkgbuwpVDdxAFRgLZLahW9Ok+c1PlzIauPxv+jIEI4rSEEJRKZG2JK3TXUdhd58mHBfQMNjKQMF+Y2wCCGjfMO0q4SgvBhYyb4oBTxEqnc2Pzh2DJdNzRFsV7ktsQSRglHGVI+1XTmQ+2kbBzNOQBLjOuRvDZENUhyxPKGZDHyAOMlVvYm8vvWebM1/F3YgDb/tPh33+EGSvpKkCZ5nUxB5e605H6gdYlNKNhuWKlEKTo2/kF0D39gAUCIcGbzw= diff --git a/packages/CLI11/CHANGELOG.md b/packages/CLI11/CHANGELOG.md new file mode 100644 index 0000000000000000000000000000000000000000..279ebe327c47642b3f895c2570b3c74cb7f742f2 --- /dev/null +++ b/packages/CLI11/CHANGELOG.md @@ -0,0 +1,191 @@ +## Version 1.4: More feedback + +This version adds lots of smaller fixes and additions after the refactor in version 1.3. More ways to download and use CLI11 in CMake have been added. INI files have improved support. + +* Lexical cast is now more strict than before [#68] and fails on overflow [#84] +* Added `get_parent()` to access the parent from a subcommand +* Added `ExistingPath` validator [#73] +* `app.allow_ini_extras()` added to allow extras in INI files [#70] +* Multiline INI comments now supported +* Descriptions can now be written with `config_to_str` [#66] +* Double printing of error message fixed [#77] +* Renamed `requires` to `needs` to avoid C++20 keyword [#75], [#82] +* MakeSingleHeader now works if outside of git [#78] +* Adding install support for CMake [#79], improved support for `find_package` [#83], [#84] +* Added support for Conan.io [#83] + +[#70]: https://github.com/CLIUtils/CLI11/issues/70 +[#75]: https://github.com/CLIUtils/CLI11/issues/75 + +[#84]: https://github.com/CLIUtils/CLI11/pull/84 +[#83]: https://github.com/CLIUtils/CLI11/pull/83 +[#82]: https://github.com/CLIUtils/CLI11/pull/82 +[#79]: https://github.com/CLIUtils/CLI11/pull/79 +[#78]: https://github.com/CLIUtils/CLI11/pull/78 +[#77]: https://github.com/CLIUtils/CLI11/pull/77 +[#73]: https://github.com/CLIUtils/CLI11/pull/73 +[#68]: https://github.com/CLIUtils/CLI11/pull/68 +[#66]: https://github.com/CLIUtils/CLI11/pull/66 + +## Version 1.3: Refactor + +This version focused on refactoring several key systems to ensure correct behavior in the interaction of different settings. Most caveats about +features only working on the main App have been addressed, and extra arguments have been reworked. Inheritance +of defaults makes configuring CLI11 much easier without having to subclass. Policies add new ways to handle multiple arguments to match your +favorite CLI programs. Error messages and help messages are better and more flexible. Several bugs and odd behaviors in the parser have been fixed. + +* Added a version macro, `CLI11_VERSION`, along with `*_MAJOR`, `*_MINOR`, and `*_PATCH`, for programmatic access to the version. +* Reworked the way defaults are set and inherited; explicit control given to user with `->option_defaults()` [#48](https://github.com/CLIUtils/CLI11/pull/48) +* Hidden options now are based on an empty group name, instead of special "hidden" keyword [#48](https://github.com/CLIUtils/CLI11/pull/48) +* `parse` no longer returns (so `CLI11_PARSE` is always usable) [#37](https://github.com/CLIUtils/CLI11/pull/37) +* Added `remaining()` and `remaining_size()` [#37](https://github.com/CLIUtils/CLI11/pull/37) +* `allow_extras` and `prefix_command` are now valid on subcommands [#37](https://github.com/CLIUtils/CLI11/pull/37) +* Added `take_last` to only take last value passed [#40](https://github.com/CLIUtils/CLI11/pull/40) +* Added `multi_option_policy` and shortcuts to provide more control than just a take last policy [#59](https://github.com/CLIUtils/CLI11/pull/59) +* More detailed error messages in a few cases [#41](https://github.com/CLIUtils/CLI11/pull/41) +* Footers can be added to help [#42](https://github.com/CLIUtils/CLI11/pull/42) +* Help flags are easier to customize [#43](https://github.com/CLIUtils/CLI11/pull/43) +* Subcommand now support groups [#46](https://github.com/CLIUtils/CLI11/pull/46) +* `CLI::RuntimeError` added, for easy exit with error codes [#45](https://github.com/CLIUtils/CLI11/pull/45) +* The clang-format script is now no longer "hidden" [#48](https://github.com/CLIUtils/CLI11/pull/48) +* The order is now preserved for subcommands (list and callbacks) [#49](https://github.com/CLIUtils/CLI11/pull/49) +* Tests now run individually, utilizing CMake 3.10 additions if possible [#50](https://github.com/CLIUtils/CLI11/pull/50) +* Failure messages are now customizable, with a shorter default [#52](https://github.com/CLIUtils/CLI11/pull/52) +* Some improvements to error codes [#53](https://github.com/CLIUtils/CLI11/pull/53) +* `require_subcommand` now offers a two-argument form and negative values on the one-argument form are more useful [#51](https://github.com/CLIUtils/CLI11/pull/51) +* Subcommands no longer match after the max required number is obtained [#51](https://github.com/CLIUtils/CLI11/pull/51) +* Unlimited options no longer prioritize over remaining/unlimited positionals [#51](https://github.com/CLIUtils/CLI11/pull/51) +* Added `->transform` which modifies the string parsed [#54](https://github.com/CLIUtils/CLI11/pull/54) +* Changed of API in validators to `void(std::string &)` (const for users), throwing providing nicer errors [#54](https://github.com/CLIUtils/CLI11/pull/54) +* Added `CLI::ArgumentMismatch` [#56](https://github.com/CLIUtils/CLI11/pull/56) and fixed missing failure if one arg expected [#55](https://github.com/CLIUtils/CLI11/issues/55) +* Support for minimum unlimited expected arguments [#56](https://github.com/CLIUtils/CLI11/pull/56) +* Single internal arg parse function [#56](https://github.com/CLIUtils/CLI11/pull/56) +* Allow options to be disabled from INI file, rename `add_config` to `set_config` [#60](https://github.com/CLIUtils/CLI11/pull/60) + +> ### Converting from CLI11 1.2: +> +> * `app.parse` no longer returns a vector. Instead, use `app.remaining(true)`. +> * `"hidden"` is no longer a special group name, instead use `""` +> * Validators API has changed to return an error string; use `.empty()` to get the old bool back +> * Use `.set_help_flag` instead of accessing the help pointer directly (discouraged, but not removed yet) +> * `add_config` has been renamed to `set_config` +> * Errors thrown in some cases are slightly more specific + +## Version 1.2: Stability + +This release focuses on making CLI11 behave properly in corner cases, and with config files on the command line. This includes fixes for a variety of reported issues. A few features were added to make life easier, as well; such as a new flag callback and a macro for the parse command. + +* Added functional form of flag [#33](https://github.com/CLIUtils/CLI11/pull/33), automatic on C++14 +* Fixed Config file search if passed on command line [#30](https://github.com/CLIUtils/CLI11/issues/30) +* Added `CLI11_PARSE(app, argc, argv)` macro for simple parse commands (does not support returning arg) +* The name string can now contain spaces around commas [#29](https://github.com/CLIUtils/CLI11/pull/29) +* `set_default_str` now only sets string, and `set_default_val` will evaluate the default string given [#26](https://github.com/CLIUtils/CLI11/issues/26) +* Required positionals now take priority over subcommands [#23](https://github.com/CLIUtils/CLI11/issues/23) +* Extra requirements enforced by Travis + +## Version 1.1: Feedback + +This release incorporates feedback from the release announcement. The examples are slowly being expanded, some corner cases improved, and some new functionality for tricky parsing situations. + +* Added simple support for enumerations, allow non-printable objects [#12](https://github.com/CLIUtils/CLI11/issues/12) +* Added `app.parse_order()` with original parse order ([#13](https://github.com/CLIUtils/CLI11/issues/13), [#16](https://github.com/CLIUtils/CLI11/pull/16)) +* Added `prefix_command()`, which is like `allow_extras` but instantly stops and returns. ([#8](https://github.com/CLIUtils/CLI11/issues/8), [#17](https://github.com/CLIUtils/CLI11/pull/17)) +* Removed Windows warning ([#10](https://github.com/CLIUtils/CLI11/issues/10), [#20](https://github.com/CLIUtils/CLI11/pull/20)) +* Some improvements to CMake, detect Python and no dependencies on Python 2 (like Python 3) ([#18](https://github.com/CLIUtils/CLI11/issues/18), [#21](https://github.com/CLIUtils/CLI11/pull/21)) + +## Version 1.0: Official release + +This is the first stable release for CLI11. Future releases will try to remain backward compatible and will follow semantic versioning if possible. There were a few small changes since version 0.9: + +* Cleanup using `clang-tidy` and `clang-format` +* Small improvements to Timers, easier to subclass Error +* Move to 3-Clause BSD license + +## Version 0.9: Polish + +This release focused on cleaning up the most exotic compiler warnings, fixing a few oddities of the config parser, and added a more natural method to check subcommands. + +* Better CMake named target (CLI11) +* More warnings added, fixed +* Ini output now includes `=false` when `default_also` is true +* Ini no longer lists the help pointer +* Added test for inclusion in multiple files and linking, fixed issues (rarely needed for CLI, but nice for tools) +* Support for complex numbers +* Subcommands now test true/false directly or with `->parsed()`, cleaner parse + +## Version 0.8: CLIUtils + +This release moved the repository to the CLIUtils master organization. + +* Moved to CLIUtils on GitHub +* Fixed docs build and a few links + +## Version 0.7: Code coverage 100% + +Lots of small bugs fixed when adding code coverage, better in edge cases. Much more powerful ini support. + +* Allow comments in ini files (lines starting with `;`) +* Ini files support flags, vectors, subcommands +* Added CodeCov code coverage reports +* Lots of small bugfixes related to adding tests to increase coverage to 100% +* Error handling now uses scoped enum in errors +* Reparsing rules changed a little to accommodate Ini files. Callbacks are now called when parsing INI, and reset any time results are added. +* Adding extra utilities in full version only, `Timer` (not needed for parsing, but useful for general CLI applications). +* Better support for custom `add_options` like functions. + +## Version 0.6: Cleanup + +Lots of cleanup and docs additions made it into this release. Parsing is simpler and more robust; fall through option added and works as expected; much more consistent variable names internally. + +* Simplified parsing to use `vector<string>` only +* Fixed fallthrough, made it optional as well (default: off): `.fallthrough()`. +* Added string versions of `->requires()` and `->excludes()` for consistency. +* Renamed protected members for internal consistency, grouped docs. +* Added the ability to add a number to `.require_subcommand()`. + +## Version 0.5: Windows support + +* Allow `Hidden` options. +* Throw `OptionAlreadyAdded` errors for matching subcommands or options, with ignore-case included, tests +* `->ignore_case()` added to subcommands, options, and `add_set_ignore_case`. Subcommands inherit setting from parent App on creation. +* Subcommands now can be "chained", that is, left over arguments can now include subcommands that then get parsed. Subcommands are now a list (`get_subcommands`). Added `got_subcommand(App_or_name)` to check for subcommands. +* Added `.allow_extras()` to disable error on failure. Parse returns a vector of leftover options. Renamed error to `ExtrasError`, and now triggers on extra options too. +* Added `require_subcommand` to `App`, to simplify forcing subcommands. Do **not** do `add_subcommand()->require_subcommand`, since that is the subcommand, not the master `App`. +* Added printout of ini file text given parsed options, skips flags. +* Support for quotes and spaces in ini files +* Fixes to allow support for Windows (added Appveyor) (Uses `-`, not `/` syntax) + +## Version 0.4: Ini support + +* Updates to help print +* Removed `run`, please use `parse` unless you subclass and add it +* Supports ini files mixed with command line, tested +* Added Range for further Plumbum compatibility +* Added function to print out ini file + +## Version 0.3: Plumbum compatibility + +* Added `->requires`, `->excludes`, and `->envname` from [Plumbum](http://plumbum.readthedocs.io/en/latest/) +* Supports `->mandatory` from Plubmum +* More tests for help strings, improvements in formatting +* Support type and set syntax in positionals help strings +* Added help groups, with `->group("name")` syntax +* Added initial support for ini file reading with `add_config` option. +* Supports GCC 4.7 again +* Clang 3.5 now required for tests due to googlemock usage, 3.4 should still work otherwise +* Changes `setup` for an explicit help bool in constructor/`add_subcommand` + +## Version 0.2: Leaner and meaner + +* Moved to simpler syntax, where `Option` pointers are returned and operated on +* Removed `make_` style options +* Simplified Validators, now only requires `->check(function)` +* Removed Combiners +* Fixed pointers to Options, stored in `unique_ptr` now +* Added `Option_p` and `App_p`, mostly for internal use +* Startup sequence, including help flag, can be modified by subclasses + +## Version 0.1: First release + +First release before major cleanup. Still has make syntax and combiners; very clever syntax but not the best or most commonly expected way to work. + diff --git a/packages/CLI11/CMakeLists.txt b/packages/CLI11/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..f31547e3b96c63be237bd20fb5089125fad2c81c --- /dev/null +++ b/packages/CLI11/CMakeLists.txt @@ -0,0 +1,178 @@ +cmake_minimum_required(VERSION 3.4 FATAL_ERROR) + +set(VERSION_REGEX "#define CLI11_VERSION[ \t]+\"(.+)\"") + +# Read in the line containing the version +file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/include/CLI/Version.hpp" + VERSION_STRING REGEX ${VERSION_REGEX}) + +# Pick out just the version +string(REGEX REPLACE ${VERSION_REGEX} "\\1" VERSION_STRING "${VERSION_STRING}") + +project(CLI11 LANGUAGES CXX VERSION ${VERSION_STRING}) + +set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH}) + +# Only if built as the main project +if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) + # User settable + set(CLI_CXX_STD "11" CACHE STRING "The CMake standard to require") + + set(CUR_PROJ ON) + set(CMAKE_CXX_STANDARD ${CLI_CXX_STD}) + set(CMAKE_CXX_EXTENSIONS OFF) + set(CMAKE_CXX_STANDARD_REQUIRED ON) + + # Be moderately paranoid with flags + if(MSVC) + add_definitions("/W4") + else() + add_definitions("-Wall -Wextra -pedantic") + endif() + + if(CMAKE_VERSION VERSION_GREATER 3.6) + # Add clang-tidy if available + option(CLANG_TIDY_FIX "Perform fixes for Clang-Tidy" OFF) + find_program( + CLANG_TIDY_EXE + NAMES "clang-tidy" + DOC "Path to clang-tidy executable" + ) + + if(CLANG_TIDY_EXE) + if(CLANG_TIDY_FIX) + set(DO_CLANG_TIDY "${CLANG_TIDY_EXE}" "-fix") + else() + set(DO_CLANG_TIDY "${CLANG_TIDY_EXE}") + endif() + endif() + endif() +else() + set(CUR_PROJ OFF) +endif() + +# Allow IDE's to group targets into folders +set_property(GLOBAL PROPERTY USE_FOLDERS ON) + +if(CMAKE_BUILD_TYPE STREQUAL Coverage) + include(CodeCoverage) + setup_target_for_coverage(CLI_coverage ctest coverage) +endif() + +file(GLOB CLI_headers "${CMAKE_CURRENT_SOURCE_DIR}/include/CLI/*") +# To see in IDE, must be listed for target + +add_library(CLI11 INTERFACE) + +# Duplicated because CMake adds the current source dir if you don't. +target_include_directories(CLI11 INTERFACE + $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> + $<INSTALL_INTERFACE:include>) + +# Make add_subdirectory work like find_package +add_library(CLI11::CLI11 ALIAS CLI11) + +# This folder should be installed +install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/CLI DESTINATION include) + +# Use find_package on the installed package +# Since we have no custom code, we can directly write this +# to Config.cmake (otherwise we'd have a custom config and would +# 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 + ) + +# Make version available in the install +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/CLI11ConfigVersion.cmake" + DESTINATION lib/cmake/CLI11) + +# Make an export target +install(TARGETS CLI11 + EXPORT CLI11Targets) + +# Install the export target as a file +install(EXPORT CLI11Targets + FILE CLI11Config.cmake + NAMESPACE CLI11:: + DESTINATION lib/cmake/CLI11) + +# Use find_package on the installed package +export(TARGETS CLI11 + NAMESPACE CLI11:: + FILE CLI11Targets.cmake) + +# Register in the user cmake package registry +export(PACKAGE CLI11) + +# Single file test +find_package(PythonInterp) +if(CUR_PROJ AND PYTHONINTERP_FOUND) + set(CLI_SINGLE_FILE_DEFAULT ON) +else() + set(CLI_SINGLE_FILE_DEFAULT OFF) +endif() + +option(CLI_SINGLE_FILE "Generate a single header file" ${CLI_SINGLE_FILE_DEFAULT}) +if(CLI_SINGLE_FILE) + find_package(PythonInterp REQUIRED) + file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/include") + add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/include/CLI11.hpp" + COMMAND "${PYTHON_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/scripts/MakeSingleHeader.py" "${CMAKE_CURRENT_BINARY_DIR}/include/CLI11.hpp" + DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/include/CLI/CLI.hpp" ${CLI_headers} + ) + add_custom_target(generate_cli_single_file ALL + DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/include/CLI11.hpp") + set_target_properties(generate_cli_single_file + PROPERTIES FOLDER "Scripts") + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/CLI11.hpp DESTINATION include) + add_library(CLI11_SINGLE INTERFACE) + target_link_libraries(CLI11_SINGLE INTERFACE CLI11) + add_dependencies(CLI11_SINGLE generate_cli_single_file) + target_compile_definitions(CLI11_SINGLE INTERFACE -DCLI_SINGLE_FILE) + target_include_directories(CLI11_SINGLE INTERFACE "${CMAKE_CURRENT_BINARY_DIR}/include/") +endif() + +option(CLI_SINGLE_FILE_TESTS "Duplicate all the tests for a single file build" OFF) + +option(CLI_TESTING "Build the tests and add them" ${CUR_PROJ}) +if(CLI_TESTING) + enable_testing() + add_subdirectory(tests) +endif() + +option(CLI_EXAMPLES "Build the examples" ${CUR_PROJ}) +if(CLI_EXAMPLES) + add_subdirectory(examples) +endif() + +if(NOT CUR_PROJ) + mark_as_advanced(CLI_SINGLE_FILE_TESTS CLI_EXAMPLES CLI_TESTING) +endif() + +# Packaging support +set(CPACK_PACKAGE_VENDOR "github.com/CLIUtils/CLI11") +set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Command line interface") +set(CPACK_PACKAGE_VERSION_MAJOR ${CLI11_VERSION_MAJOR}) +set(CPACK_PACKAGE_VERSION_MINOR ${CLI11_VERSION_MINOR}) +set(CPACK_PACKAGE_VERSION_PATCH ${CLI11_VERSION_PATCH}) +set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE") +set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md") +set(CPACK_SOURCE_GENERATOR "TGZ;ZIP") +# CPack collects *everything* except what's listed here. +set(CPACK_SOURCE_IGNORE_FILES + /.git + /dist + /.*build.* + /\\\\.DS_Store + /.*\\\\.egg-info + /var + /Pipfile.*$ +) +include(CPack) + diff --git a/packages/CLI11/CONTRIBUTING.md b/packages/CLI11/CONTRIBUTING.md new file mode 100644 index 0000000000000000000000000000000000000000..f4a67842a0350a8f43366649ee1dbc434268d094 --- /dev/null +++ b/packages/CLI11/CONTRIBUTING.md @@ -0,0 +1,20 @@ + +Thanks for considering to write a Pull Request (PR) for CLI11! Here are a few guidelines to get you started: + +Make sure you are comfortable with the license; all contributions are licensed under the original license. + +## Adding functionality +Make sure any new functions you add are are: + +* Documented by `///` documentation for Doxygen +* Mentioned in the instructions in the README, though brief mentions are okay +* Explained in your PR (or previously explained in an Issue mentioned in the PR) +* Completely covered by tests + +In general, make sure the addition is well thought out and does not increase the complexity of CLI11 if possible. + +## Things you should know: + +* Once you make the PR, tests will run to make sure your code works on all supported platforms +* The test coverage is also measured, and that should remain 100% +* Formatting should be done with clang-format, otherwise the format check will not pass. However, it is trivial to apply this to your PR, so don't worry about this check. If you do have clang-format, just run `scripts/check_style.sh` diff --git a/packages/CLI11/LICENSE b/packages/CLI11/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..ac56c9881192b8417cb9fdcf3af5344a6cd44f8f --- /dev/null +++ b/packages/CLI11/LICENSE @@ -0,0 +1,11 @@ +CLI11 1.0 Copyright (c) 2017 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 modification, are permitted provided that the following conditions are met: +1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. +3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + diff --git a/packages/CLI11/README.md b/packages/CLI11/README.md new file mode 100644 index 0000000000000000000000000000000000000000..f2c2cf0a11a0678a7934d0b8e6dc09ec9990d72e --- /dev/null +++ b/packages/CLI11/README.md @@ -0,0 +1,438 @@ +[![Build Status Linux and macOS][travis-badge]][Travis] +[![Build Status Windows][appveyor-badge]][AppVeyor] +[![Code Coverage][codecov-badge]][CodeCov] +[![Join the chat at https://gitter.im/CLI11gitter/Lobby][gitter-badge]][gitter] +[![License: BSD][license-badge]](./LICENSE) +[![Latest release][releases-badge]][Github Releases] +[![DOI][DOI-badge]][DOI-link] +[![Conan.io][conan-badge]][conan-link] + +[Documentation][GitBook] • +[API Reference][api-docs] • +[What's new](./CHANGELOG.md) • +[Try CLI11 1.4 online][wandbox-link] + +# CLI11: Command line parser for C++11 + +CLI11 provides all the features you expect in a powerful command line parser, with a beautiful, minimal syntax and no dependencies beyond C++11. It is header only, and comes in a single file form for easy inclusion in projects. It is easy to use for small projects, but powerful enough for complex command line projects, and can be customized for frameworks. +It is tested on [Travis] and [AppVeyor], and is being included in the [GooFit GPU fitting framework][GooFit]. It was inspired by [`plumbum.cli`][Plumbum] for Python. CLI11 has a user friendly introduction in this README, a more in-depth tutorial [GitBook], as well as [API documentation][api-docs] generated by Travis. +See the [changelog](./CHANGELOG.md) or [GitHub Releases] for details for current and past releases. Also see the [Version 1.0 post] and [Version 1.3 post] for more information. + +You can be notified when new releases are made by subscribing to https://github.com/CLIUtils/CLI11/releases.atom on an RSS reader, like Feedly. + +### Why write another CLI parser? + +An acceptable CLI parser library should be all of the following: + +* Easy to include (i.e., header only, one file if possible, **no external requirements**): While many programs depend on Boost, that should not be a requirement if all you want is CLI parsing. +* Short Syntax: This is one of the main points of a CLI parser, it should make variables from the command line nearly as easy to define as any other variables. If most of your program is hidden in CLI parsing, this is a problem for readability. +* C++11 or better: Should work with GCC 4.7+ (such as GCC 4.8 on CentOS 7) or above, or Clang 3.5+, or MSVC 2015+. (Note: for CLI11, Clang 3.4 only fails because of tests, GoogleMock does not support it.) +* Work on Linux, macOS, and Windows. +* Well tested using [Travis] (Linux and macOS) and [AppVeyor] (Windows). "Well" is defined as having good coverage measured by [CodeCov]. +* Clear help printing. +* Nice error messages. +* Standard shell idioms supported naturally, like grouping flags, a positional separator, etc. +* Easy to execute, with help, parse errors, etc. providing correct exit and details. +* Easy to extend as part of a framework that provides "applications" to users. +* Usable subcommand syntax, with support for multiple subcommands, nested subcommands, and optional fallthrough (explained later). +* Ability to add a configuration file (`ini` format), and produce it as well. +* Produce real values that can be used directly in code, not something you have pay compute time to look up, for HPC applications. +* Work with standard types, simple custom types, and extendible to exotic types. +* Permissively licensed. + +<details><summary>The major CLI parsers for C++ include, with my biased opinions: (click to expand)</summary><p> + +| Library | My biased opinion | +|---------|-------------------| +| [Boost Program Options] | A great library if you already depend on Boost, but its pre-C++11 syntax is really odd and setting up the correct call in the main function is poorly documented (and is nearly a page of code). A simple wrapper for the Boost library was originally developed, but was discarded as CLI11 became more powerful. The idea of capturing a value and setting it originated with Boost PO. [See this comparison.][cli11-po-compare] | +| [The Lean Mean C++ Option Parser] | One header file is great, but the syntax is atrocious, in my opinion. It was quite impractical to wrap the syntax or to use in a complex project. It seems to handle standard parsing quite well. | +| [TCLAP] | The not-quite-standard command line parsing causes common shortcuts to fail. It also seems to be poorly supported, with only minimal bugfixes accepted. Header only, but in quite a few files. Has not managed to get enough support to move to GitHub yet. No subcommands. Produces wrapped values. | +| [Cxxopts] | C++11, single file, and nice CMake support, but requires regex, therefore GCC 4.8 (CentOS 7 default) does not work. Syntax closely based on Boost PO, so not ideal but familiar. | +| [DocOpt] | Completely different approach to program options in C++11, you write the docs and the interface is generated. Too fragile and specialized. | + +After I wrote this, I also found the following libraries: + +| Library | My biased opinion | +|---------|-------------------| +| [GFlags] | The Google Commandline Flags library. Uses macros heavily, and is limited in scope, missing things like subcommands. It provides a simple syntax and supports config files/env vars. | +| [GetOpt] | Very limited C solution with long, convoluted syntax. Does not support much of anything, like help generation. Always available on UNIX, though (but in different flavors). | +| [ProgramOptions.hxx] | Intresting library, less powerful and no subcommands. Nice callback system. | +| [Args] | Also interesting, and supports subcommands. I like the optional-like design, but CLI11 is cleaner and provides direct value access, and is less verbose. | +| [Argument Aggregator] | I'm a big fan of the [fmt] library, and the try-catch statement looks familiar. :thumbsup: Doesn't seem to support subcommands. | +| [Clara] | Simple library built for the excellent [Catch] testing framework. Unique syntax, limited scope. | +| [Argh!] | Very minimalistic C++11 parser, single header. Don't have many features. No help generation?!?! At least it's exception-free.| +| [CLI] | Custom language and parser. Huge build-system overkill for very little benefit. Last release in 2009, but still occasionally active. | + +See [Awesome C++] for a less-biased list of parsers. + +</p></details> +<br/> + +None of these libraries fulfill all the above requirements, or really even come close. As you probably have already guessed, CLI11 does. +So, this library was designed to provide a great syntax, good compiler compatibility, and minimal installation fuss. + +## Features not supported by this library + +There are some other possible "features" that are intentionally not supported by this library: + +* Non-standard variations on syntax, like `-long` options. This is non-standard and should be avoided, so that is enforced by this library. +* Completion of partial options, such as Python's `argparse` supplies for incomplete arguments. It's better not to guess. Most third party command line parsers for python actually reimplement command line parsing rather than using argparse because of this perceived design flaw. +* In C++14, you could have a set of `callback` methods with differing signatures (tested in a branch). Not deemed worth having a C++14 variation on API and removed. +* Autocomplete: This might eventually be added to both Plumbum and CLI11, but it is not supported yet. +* Wide strings / unicode: Since this uses the standard library only, it might be hard to properly implement, but I would be open to suggestions in how to do this. + + +## Installing + +To use, there are two methods: + +1. Copy `CLI11.hpp` from the [most recent release][Github Releases] into your include directory, and you are set. This is combined from the source files for every release. This includes the entire command parser library, but does not include separate utilities (like `Timer`, `AutoTimer`). The utilities are completely self contained and can be copied separately. +2. Use `CLI/*.hpp` files. You could check out the repository as a submodule, for example. You can use the `CLI11::CLI11` interface target when linking from `add_subdirectory`. You can also configure and optionally install the project, and then use `find_package(CLI11 CONFIG)` to get the `CLI11::CLI11` target. You can also use [Conan.io][conan-link]. (These are just conveniences to allow you to use your favorite method of managing packages; it's just header only so including the correct path and + using C++11 is all you really need.) + +To build the tests, checkout the repository and use CMake: + +```bash +mkdir build +cd build +cmake .. +make +GTEST_COLOR=1 CTEST_OUTPUT_ON_FAILURE=1 make test +``` + +## Adding options + +To set up, add options, and run, your main function will look something like this: + +```cpp +CLI::App app{"App description"}; + +std::string filename = "default"; +app.add_option("-f,--file", filename, "A help string"); + +CLI11_PARSE(app, argc, argv); +``` + +<details><summary>Note: If you don't like macros, this is what that macro expands to: (click to expand)</summary><p> + +```cpp +try { + app.parse(argc, argv); +} catch (const CLI::ParseError &e) { + return app.exit(e); +} +``` + +The try/catch block ensures that `-h,--help` or a parse error will exit with the correct return code (selected from `CLI::ExitCodes`). (The return here should be inside `main`). You should not assume that the option values have been set inside the catch block; for example, help flags intentionally short-circuit all other processing for speed and to ensure required options and the like do not interfere. + +</p></details> +</br> + + +The initialization is just one line, adding options is just two each. The parse macro is just one line (or 5 for the contents of the macro). After the app runs, the filename will be set to the correct value if it was passed, otherwise it will be set to the default. You can check to see if this was passed on the command line with `app.count("--file")`. + +The supported values are: + +```cpp +app.add_option(option_name, + variable_to_bind_to, // int, float, vector, or string-like + help_string="", + default=false) + +app.add_complex(... // Special case: support for complex numbers + +app.add_flag(option_name, + int_or_bool = nothing, + help_string="") + +app.add_flag_function(option_name, + function <void(size_t count)>, + help_string="") + +app.add_set(option_name, + variable_to_bind_to, + set_of_possible_options, + help_string="", + default=false) + +app.add_set_ignore_case(... // String only + +App* subcom = app.add_subcommand(name, discription); +``` + +An option name must start with a alphabetic character or underscore. For long options, anything but an equals sign or a comma is valid after that. Names are given as a comma separated string, with the dash or dashes. An option or flag can have as many names as you want, and afterward, using `count`, you can use any of the names, with dashes as needed, to count the options. One of the names is allowed to be given without proceeding dash(es); if present the option is a positional option, and that name will be used on help line for its positional form. If you want the default value to print in the help description, pass in `true` for the final parameter for `add_option` or `add_set`. The set options allow your users to pick from a set of predefined options. + +On a C++14 compiler, you can pass a callback function directly to `.add_flag`, while in C++11 mode you'll need to use `.add_flag_function` if you want a callback function. The function will be given the number of times the flag was passed. You can throw a relevant `CLI::ParseError` to signal a failure. + +### Example + +* `"one,-o,--one"`: Valid as long as not a flag, would create an option that can be specified positionally, or with `-o` or `--one` +* `"this"` Can only be passed positionally +* `"-a,-b,-c"` No limit to the number of non-positional option names + + +The add commands return a pointer to an internally stored `Option`. If you set the final argument to true, the default value is captured and printed on the command line with the help flag. This option can be used directly to check for the count (`->count()`) after parsing to avoid a string based lookup. Before parsing, you can set the following options: + +* `->required()`: The program will quit if this option is not present. This is `mandatory` in Plumbum, but required options seems to be a more standard term. For compatibility, `->mandatory()` also works. +* `->expected(N)`: Take `N` values instead of as many as possible, only for vector args. If negative, require at least `-N`. +* `->needs(opt)`: This option requires another option to also be present, opt is an `Option` pointer. +* `->excludes(opt)`: This option cannot be given with `opt` present, opt is an `Option` pointer. +* `->envname(name)`: Gets the value from the environment if present and not passed on the command line. +* `->group(name)`: The help group to put the option in. No effect for positional options. Defaults to `"Options"`. `""` will not show up in the help print (hidden). +* `->ignore_case()`: Ignore the case on the command line (also works on subcommands, does not affect arguments). +* `->multi_option_policy(CLI::MultiOptionPolicy::Throw)`: Set the multi-option policy. Shortcuts available: `->take_last()`, `->take_first()`, and `->join()`. This will only affect options expecting 1 argument or bool flags (which always default to take last). +* `->check(CLI::ExistingFile)`: Requires that the file exists if given. +* `->check(CLI::ExistingDirectory)`: Requires that the directory exists. +* `->check(CLI::ExistingPath)`: Requires that the path (file or directory) exists. +* `->check(CLI::NonexistentPath)`: Requires that the path does not exist. +* `->check(CLI::Range(min,max))`: Requires that the option be between min and max (make sure to use floating point if needed). Min defaults to 0. +* `->transform(std::string(std::string))`: Converts the input string into the output string, in-place in the parsed options. +* `->configurable(false)`: Disable this option from being in an ini configuration file. + +These options return the `Option` pointer, so you can chain them together, and even skip storing the pointer entirely. Check takes any function that has the signature `void(const std::string&)`; it should throw a `ValidationError` when validation fails. The help message will have the name of the parent option prepended. Since `check` and `transform` use the same underlying mechanism, you can chain as many as you want, and they will be executed in order. If you just want to see the unconverted values, use `.results()` to get the `std::vector<std::string>` of results. + + +On the command line, options can be given as: + +* `-a` (flag) +* `-abc` (flags can be combined) +* `-f filename` (option) +* `-ffilename` (no space required) +* `-abcf filename` (flags and option can be combined) +* `--long` (long flag) +* `--file filename` (space) +* `--file=filename` (equals) + +Extra positional arguments will cause the program to exit, so at least one positional option with a vector is recommended if you want to allow extraneous arguments. +If you set `.allow_extras()` on the main `App`, you will not get an error. You can access the missing options using `remaining` (if you have subcommands, `app.remaining(true)` will get all remaining options, subcommands included). + +You can access a vector of pointers to the parsed options in the original order using `parse_order()`. +If `--` is present in the command line, +everything after that is positional only. + + + +## Subcommands + +Subcommands are supported, and can be nested infinitely. To add a subcommand, call the `add_subcommand` method with a name and an optional description. This gives a pointer to an `App` that behaves just like the main app, and can take options or further subcommands. Add `->ignore_case()` to a subcommand to allow any variation of caps to also be accepted. Children inherit the current setting from the parent. You cannot add multiple matching subcommand names at the same level (including ignore +case). + +If you want to require that at least one subcommand is given, use `.require_subcommand()` on the parent app. You can optionally give an exact number of subcommands to require, as well. If you give two arguments, that sets the min and max number allowed. +0 for the max number allowed will allow an unlimited number of subcommands. As a handy shortcut, a single negative value N will set "up to N" values. Limiting the maximimum number allows you to keep arguments that match a previous +subcommand name from matching. + +If an `App` (main or subcommand) has been parsed on the command line, `->parsed` will be true (or convert directly to bool). +All `App`s have a `get_subcommands()` method, which returns a list of pointers to the subcommands passed on the command line. A `got_subcommand(App_or_name)` method is also provided that will check to see if an `App` pointer or a string name was collected on the command line. + +For many cases, however, using an app's callback may be easier. Every app executes a callback function after it parses; just use a lambda function (with capture to get parsed values) to `.set_callback`. If you throw `CLI::Success` or `CLI::RuntimeError(return_value)`, you can +even exit the program through the callback. The main `App` has a callback slot, as well, but it is generally not as useful. +You are allowed to throw `CLI::Success` in the callbacks. +Multiple subcommands are allowed, to allow [`Click`][Click] like series of commands (order is preserved). + +There are several options that are supported on the main app and subcommands. These are: + +* `.ignore_case()`: Ignore the case of this subcommand. Inherited by added subcommands, so is usually used on the main `App`. +* `.fallthrough()`: Allow extra unmatched options and positionals to "fall through" and be matched on a parent command. Subcommands always are allowed to fall through. +* `.require_subcommand()`: Require 1 or more subcommands. +* `.require_subcommand(N)`: Require `N` subcommands if `N>0`, or up to `N` if `N<0`. `N=0` resets to the default 0 or more. +* `.require_subcommand(min, max)`: Explicitly set min and max allowed subcommands. Setting `max` to 0 is unlimited. +* `.add_subcommand(name, description="")` Add a subcommand, returns a pointer to the internally stored subcommand. +* `.got_subcommand(App_or_name)`: Check to see if a subcommand was received on the command line +* `.get_subcommands()`: The list of subcommands given on the command line +* `.get_parent()`: Get the parent App or nullptr if called on master App **Coming in version 1.4** +* `.parsed()`: True if this subcommand was given on the command line +* `.set_callback(void() function)`: Set the callback that runs at the end of parsing. The options have already run at this point. +* `.allow_extras()`: Do not throw an error if extra arguments are left over +* `.prefix_command()`: Like `allow_extras`, but stop immediately on the first unrecognised item. It is ideal for allowing your app or subcommand to be a "prefix" to calling another app. +* `.set_footer(message)`: Set text to appear at the bottom of the help string. +* `.set_failure_message(func)`: Set the failure message function. Two provided: `CLI::FailureMessage::help` and `CLI::FailureMessage::simple` (the default). +* `.group(name)`: Set a group name, defaults to `"Subcommands"`. Setting `""` will be hide the subcommand. + +> Note: if you have a fixed number of required positional options, that will match before subcommand names. + +## Configuration file + +```cpp +app.set_config(option_name="", + default_file_name="", + help_string="Read an ini file", + required=false) +``` + +If this is called with no arguments, it will remove the configuration file option (like `set_help_flag`). Setting a configuration option is special. If it is present, it will be read along with the normal command line arguments. The file will be read if it exists, and does not throw an error unless `required` is `true`. Configuration files are in `ini` format. An example of a file: + +```ini +; Commments are supported, using a ; +; The default section is [default], case insensitive + +value = 1 +str = "A string" +vector = 1 2 3 + +; Section map to subcommands +[subcommand] +in_subcommand = Wow +sub.subcommand = true +``` + +Spaces before and after the name and argument are ignored. Multiple arguments are separated by spaces. One set of quotes will be removed, preserving spaces (the same way the command line works). Boolean options can be `true`, `on`, `1`, `yes`; or `false`, `off`, `0`, `no` (case insensitive). Sections (and `.` separated names) are treated as subcommands (note: this does not mean that subcommand was passed, it just sets the "defaults". To print a configuration file from the passed +arguments, use `.config_to_str(default_also=false, prefix="", write_description=false)`, where `default_also` will also show any defaulted arguments, `prefix` will add a prefix, and `write_description` will include option descriptions. + +## Inheriting defaults + +Many of the defaults for subcommands and even options are inherited from their creators. The inherited default values for subcommands are `allow_extras`, `prefix_command`, `ignore_case`, `fallthrough`, `group`, `footer`, and maximum number of required subcommands. The help flag existence, name, and description are inherited, as well. + +Options have defaults for `group`, `required`, `multi_option_policy`, and `ignore_case`. To set these defaults, you should set the `option_defaults()` object, for example: + +```cpp +app.option_defaults()->required(); +// All future options will be required +``` + +The default settings for options are inherited to subcommands, as well. + +## Subclassing + +The App class was designed allow toolkits to subclass it, to provide preset default options (see above) and setup/teardown code. Subcommands remain an unsubclassed `App`, since those are not expected to need setup and teardown. The default `App` only adds a help flag, `-h,--help`, than can removed/replaced using `.set_help_flag(name, help_string)`. You can remove options if you have pointers to them using `.remove_option(opt)`. You can add a `pre_callback` override to customize the after parse +but before run behavior, while +still giving the user freedom to `set_callback` on the main app. + +The most important parse function is `parse(std::vector<std::string>)`, which takes a reversed list of arguments (so that `pop_back` processes the args in the correct order). `get_help_ptr` and `get_config_ptr` give you access to the help/config option pointers. The standard `parse` manually sets the name from the first argument, so it should not be in this vector. + +Also, in a related note, the `App` you get a pointer to is stored in the parent `App` in a `unique_ptr`s (like `Option`s) and are deleted when the main `App` goes out of scope. + + +## How it works + +Every `add_` option you have seen so far depends on one method that takes a lambda function. Each of these methods is just making a different lambda function with capture to populate the option. The function has full access to the vector of strings, so it knows how many times an option was passed or how many arguments it received (flags add empty strings to keep the counts correct). The lambda returns `true` if it could validate the option strings, and +`false` if it failed. If you wanted to extend this to support a new type, just use a lambda. An example of a new parser for `complex<double>` that supports all of the features of a standard `add_options` call is in [one of the tests](./tests/NewParseTest.cpp). A simpler example is shown below: + +### Example + +```cpp +app.add_option("--fancy-count", [](std::vector<std::string> val){ + std::cout << "This option was given " << val.size() << " times." << std::endl + }); +``` + +## Utilities + +There are a few other utilities that are often useful in CLI programming. These are in separate headers, and do not appear in `CLI11.hpp`, but are completely independent and can be used as needed. The `Timer`/`AutoTimer` class allows you to easily time a block of code, with custom print output. + +```cpp +{ +CLI::AutoTimer timer {"My Long Process", CLI::Timer::Big}; +some_long_running_process(); +} +``` + +This will create a timer with a title (default: `Timer`), and will customize the output using the predefined `Big` output (default: `Simple`). Because it is an `AutoTimer`, it will print out the time elapsed when the timer is destroyed at the end of the block. If you use `Timer` instead, you can use `to_string` or `std::cout << timer << std::endl;` to print the time. The print function can be any function that takes two strings, the title and the time, and returns a formatted +string for printing. + +## Other libraries + +If you use the excellent [Rang] library to add color to your terminal in a safe, multi-platform way, you can combine it with CLI11 nicely: + +```cpp +std::atexit([](){std::cout << rang::style::reset;}); +try { + app.parse(argc, argv); +} catch (const CLI::ParseError &e) { + std::cout << (e.get_exit_code()==0 ? rang::fg::blue : rang::fg::red); + return app.exit(e); +} +``` + +This will print help in blue, errors in red, and will reset before returning the terminal to the user. + +If you are on a Unix-like system, and you'd like to handle control-c and color, you can add: + +```cpp + #include <csignal> + void signal_handler(int s) { + std::cout << std::endl << rang::style::reset << rang::fg::red << rang::fg::bold; + std::cout << "Control-C detected, exiting..." << rang::style::reset << std::endl; + std::exit(1); // will call the correct exit func, no unwinding of the stack though + } +``` + +And, in your main function: + +```cpp + // Nice Control-C + struct sigaction sigIntHandler; + sigIntHandler.sa_handler = signal_handler; + sigemptyset(&sigIntHandler.sa_mask); + sigIntHandler.sa_flags = 0; + sigaction(SIGINT, &sigIntHandler, nullptr); +``` + +## Contributing + +To contribute, open an [issue][Github Issues] or [pull request][Github Pull Requests] on GitHub, or ask a question on [gitter]. The is also a short note to contributors [here](./CONTRIBUTING.md). + +As of version 1.0, this library is available under a 3-Clause BSD license. See the [LICENSE](./LICENSE) file for details. + +This project was created by [Henry Schreiner](https://github.com/henryiii). +Significant features and/or improvements to the code were contributed by: + +* [Marcus Brinkmann](https://github.com/lambdafu) +* [Jonas Nilsson](https://github.com/SkyToGround) +* [Doug Johnston](https://github.com/dvj) +* [Lucas Czech](https://github.com/lczech) +* [Mathias Soeken](https://github.com/msoeken) +* [Nathan Hourt](https://github.com/nathanhourt) + + +CLI11 was developed at the [University of Cincinnati] to support of the [GooFit] library under [NSF Award 1414736]. Version 0.9 was featured in a [DIANA/HEP] meeting at CERN ([see the slides][DIANA slides]). Please give it a try! Feedback is always welcome. + + +[DOI-badge]: https://zenodo.org/badge/80064252.svg +[DOI-link]: https://zenodo.org/badge/latestdoi/80064252 +[travis-badge]: https://img.shields.io/travis/CLIUtils/CLI11/master.svg?label=Linux/macOS +[Travis]: https://travis-ci.org/CLIUtils/CLI11 +[appveyor-badge]: https://img.shields.io/appveyor/ci/HenrySchreiner/cli11/master.svg?label=Windows +[AppVeyor]: https://ci.appveyor.com/project/HenrySchreiner/cli11 +[codecov-badge]: https://codecov.io/gh/CLIUtils/CLI11/branch/master/graph/badge.svg +[CodeCov]: https://codecov.io/gh/CLIUtils/CLI11 +[gitter-badge]: https://badges.gitter.im/CLI11gitter/Lobby.svg +[gitter]: https://gitter.im/CLI11gitter/Lobby +[license-badge]: https://img.shields.io/badge/License-BSD-blue.svg +[conan-badge]: https://api.bintray.com/packages/cliutils/CLI11/CLI11/images/download.svg +[conan-link]: https://bintray.com/cliutils/CLI11/CLI11/_latestVersion +[Github Releases]: https://github.com/CLIUtils/CLI11/releases +[Github Issues]: https://github.com/CLIUtils/CLI11/issues +[Github Pull Requests]: https://github.com/CLIUtils/CLI11/pulls +[GooFit]: https://GooFit.github.io +[Plumbum]: https://plumbum.readthedocs.io/en/latest/ +[Click]: http://click.pocoo.org +[api-docs]: https://CLIUtils.github.io/CLI11/index.html +[Rang]: https://github.com/agauniyal/rang +[Boost Program Options]: http://www.boost.org/doc/libs/1_63_0/doc/html/program_options.html +[The Lean Mean C++ Option Parser]: http://optionparser.sourceforge.net +[TCLAP]: http://tclap.sourceforge.net +[Cxxopts]: https://github.com/jarro2783/cxxopts +[DocOpt]: https://github.com/docopt/docopt.cpp +[ROOT]: https://root.cern.ch +[cltools-cmake]: https://github.com/CLIUtils/cmake +[GFlags]: https://gflags.github.io/gflags +[GetOpt]: https://www.gnu.org/software/libc/manual/html_node/Getopt.html +[DIANA/HEP]: http://diana-hep.org +[NSF Award 1414736]: https://nsf.gov/awardsearch/showAward?AWD_ID=1414736 +[University of Cincinnati]: http://www.uc.edu +[GitBook]: https://cliutils.gitlab.io/CLI11Tutorial +[ProgramOptions.hxx]: https://github.com/Fytch/ProgramOptions.hxx +[Argument Aggregator]: https://github.com/vietjtnguyen/argagg +[Args]: https://github.com/Taywee/args +[Argh!]: https://github.com/adishavit/argh +[fmt]: https://github.com/fmtlib/fmt +[Catch]: https://github.com/philsquared/Catch +[Clara]: https://github.com/philsquared/Clara +[Version 1.0 post]: https://iscinumpy.gitlab.io/post/announcing-cli11-10/ +[Version 1.3 post]: https://iscinumpy.gitlab.io/post/announcing-cli11-13/ +[wandbox-online]: https://img.shields.io/badge/try%20it-online-orange.svg +[wandbox-link]: https://wandbox.org/permlink/g7tRkuU8xY3aTIVP +[releases-badge]: https://img.shields.io/github/release/CLIUtils/CLI11.svg +[cli11-po-compare]: https://iscinumpy.gitlab.io/post/comparing-cli11-and-boostpo/ +[DIANA slides]: https://indico.cern.ch/event/619465/contributions/2507949/attachments/1448567/2232649/20170424-diana-2.pdf +[Awesome C++]: https://github.com/fffaraz/awesome-cpp/blob/master/README.md#cli diff --git a/packages/CLI11/cmake/AddGoogletest.cmake b/packages/CLI11/cmake/AddGoogletest.cmake new file mode 100644 index 0000000000000000000000000000000000000000..80eb9ed6e428ff6a41404f4265d52da89ccfe262 --- /dev/null +++ b/packages/CLI11/cmake/AddGoogletest.cmake @@ -0,0 +1,82 @@ +# +# +# Downloads GTest and provides a helper macro to add tests. Add make check, as well, which +# gives output on failed tests without having to set an environment variable. +# +# +set(UPDATE_DISCONNECTED_IF_AVAILABLE "UPDATE_DISCONNECTED 1") + +include(DownloadProject) +download_project(PROJ googletest + GIT_REPOSITORY https://github.com/google/googletest.git + GIT_TAG release-1.8.0 + UPDATE_DISCONNECTED 1 + QUIET +) + +set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) + +# CMake warning suppression will not be needed in version 1.9 +set(CMAKE_SUPPRESS_DEVELOPER_WARNINGS 1 CACHE BOOL "") +add_subdirectory(${googletest_SOURCE_DIR} ${googletest_SOURCE_DIR} EXCLUDE_FROM_ALL) +unset(CMAKE_SUPPRESS_DEVELOPER_WARNINGS) + +if (CMAKE_CONFIGURATION_TYPES) + add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} + --force-new-ctest-process --output-on-failure + --build-config "$<CONFIGURATION>") +else() + add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} + --force-new-ctest-process --output-on-failure) +endif() +set_target_properties(check PROPERTIES FOLDER "Scripts") + +#include_directories(${gtest_SOURCE_DIR}/include) + +# More modern way to do the last line, less messy but needs newish CMake: +# target_include_directories(gtest INTERFACE ${gtest_SOURCE_DIR}/include) + + +if(GOOGLE_TEST_INDIVIDUAL) + if(NOT CMAKE_VERSION VERSION_LESS 3.9) + include(GoogleTest) + else() + set(GOOGLE_TEST_INDIVIDUAL OFF) + endif() +endif() + +# Target must already exist +macro(add_gtest TESTNAME) + target_link_libraries(${TESTNAME} PUBLIC gtest gmock gtest_main) + + if(GOOGLE_TEST_INDIVIDUAL) + if(CMAKE_VERSION VERSION_LESS 3.10) + gtest_add_tests(TARGET ${TESTNAME} + TEST_PREFIX "${TESTNAME}." + TEST_LIST TmpTestList) + else() + gtest_discover_tests(${TESTNAME} + TEST_PREFIX "${TESTNAME}." + ) + + endif() + else() + add_test(${TESTNAME} ${TESTNAME}) + endif() + set_target_properties(${TESTNAME} PROPERTIES FOLDER "Tests") + +endmacro() + +mark_as_advanced( +gmock_build_tests +gtest_build_samples +gtest_build_tests +gtest_disable_pthreads +gtest_force_shared_crt +gtest_hide_internal_symbols +BUILD_GMOCK +BUILD_GTEST +) + +set_target_properties(gtest gtest_main gmock gmock_main + PROPERTIES FOLDER "Extern") diff --git a/packages/CLI11/cmake/CodeCoverage.cmake b/packages/CLI11/cmake/CodeCoverage.cmake new file mode 100644 index 0000000000000000000000000000000000000000..879e8e59c9d4302843dbf098980f9be1237be6d8 --- /dev/null +++ b/packages/CLI11/cmake/CodeCoverage.cmake @@ -0,0 +1,198 @@ +# Copyright (c) 2012 - 2015, Lars Bilke +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors +# may be used to endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# +# +# 2012-01-31, Lars Bilke +# - Enable Code Coverage +# +# 2013-09-17, Joakim Söderberg +# - Added support for Clang. +# - Some additional usage instructions. +# +# USAGE: + +# 0. (Mac only) If you use Xcode 5.1 make sure to patch geninfo as described here: +# http://stackoverflow.com/a/22404544/80480 +# +# 1. Copy this file into your cmake modules path. +# +# 2. Add the following line to your CMakeLists.txt: +# INCLUDE(CodeCoverage) +# +# 3. Set compiler flags to turn off optimization and enable coverage: +# SET(CMAKE_CXX_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage") +# SET(CMAKE_C_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage") +# +# 3. Use the function SETUP_TARGET_FOR_COVERAGE to create a custom make target +# which runs your test executable and produces a lcov code coverage report: +# Example: +# SETUP_TARGET_FOR_COVERAGE( +# my_coverage_target # Name for custom target. +# test_driver # Name of the test driver executable that runs the tests. +# # NOTE! This should always have a ZERO as exit code +# # otherwise the coverage generation will not complete. +# coverage # Name of output directory. +# ) +# +# 4. Build a Debug build: +# cmake -DCMAKE_BUILD_TYPE=Debug .. +# make +# make my_coverage_target +# +# + +# Check prereqs + +FIND_PROGRAM( GCOV_PATH gcov) +FIND_PROGRAM( LCOV_PATH lcov ) +FIND_PROGRAM( GENHTML_PATH genhtml ) +FIND_PROGRAM( GCOVR_PATH gcovr PATHS ${CMAKE_SOURCE_DIR}/tests) + +IF(NOT GCOV_PATH) + MESSAGE(FATAL_ERROR "gcov not found! Aborting...") +ENDIF() # NOT GCOV_PATH + +IF("${CMAKE_CXX_COMPILER_ID}" MATCHES "(Apple)?[Cc]lang") + IF("${CMAKE_CXX_COMPILER_VERSION}" VERSION_LESS 3) + MESSAGE(FATAL_ERROR "Clang version must be 3.0.0 or greater! Aborting...") + ENDIF() +ELSEIF(NOT CMAKE_COMPILER_IS_GNUCXX) + MESSAGE(FATAL_ERROR "Compiler is not GNU gcc! Aborting...") +ENDIF() # CHECK VALID COMPILER + +SET(CMAKE_CXX_FLAGS_COVERAGE + "-g -O0 --coverage" + CACHE STRING "Flags used by the C++ compiler during coverage builds." + FORCE ) +SET(CMAKE_C_FLAGS_COVERAGE + "-g -O0 --coverage" + CACHE STRING "Flags used by the C compiler during coverage builds." + FORCE ) +SET(CMAKE_EXE_LINKER_FLAGS_COVERAGE + "--coverage" + CACHE STRING "Flags used for linking binaries during coverage builds." + FORCE ) +SET(CMAKE_SHARED_LINKER_FLAGS_COVERAGE + "--coverage" + CACHE STRING "Flags used by the shared libraries linker during coverage builds." + FORCE ) +MARK_AS_ADVANCED( + CMAKE_CXX_FLAGS_COVERAGE + CMAKE_C_FLAGS_COVERAGE + CMAKE_EXE_LINKER_FLAGS_COVERAGE + CMAKE_SHARED_LINKER_FLAGS_COVERAGE ) + +IF ( NOT (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "Coverage")) + MESSAGE( WARNING "Code coverage results with an optimized (non-Debug) build may be misleading" ) +ENDIF() # NOT CMAKE_BUILD_TYPE STREQUAL "Debug" + + +# Param _targetname The name of new the custom make target +# Param _testrunner The name of the target which runs the tests. +# MUST return ZERO always, even on errors. +# If not, no coverage report will be created! +# Param _outputname lcov output is generated as _outputname.info +# HTML report is generated in _outputname/index.html +# Optional fourth parameter is passed as arguments to _testrunner +# Pass them in list form, e.g.: "-j;2" for -j 2 +FUNCTION(SETUP_TARGET_FOR_COVERAGE _targetname _testrunner _outputname) + + IF(NOT LCOV_PATH) + MESSAGE(FATAL_ERROR "lcov not found! Aborting...") + ENDIF() # NOT LCOV_PATH + + IF(NOT GENHTML_PATH) + MESSAGE(FATAL_ERROR "genhtml not found! Aborting...") + ENDIF() # NOT GENHTML_PATH + + SET(coverage_info "${CMAKE_BINARY_DIR}/${_outputname}.info") + SET(coverage_cleaned "${coverage_info}.cleaned") + + SEPARATE_ARGUMENTS(test_command UNIX_COMMAND "${_testrunner}") + + # Setup target + ADD_CUSTOM_TARGET(${_targetname} + + # Cleanup lcov + ${LCOV_PATH} --directory . --zerocounters + + # Run tests + COMMAND ${test_command} ${ARGV3} + + # Capturing lcov counters and generating report + COMMAND ${LCOV_PATH} --directory . --capture --output-file ${coverage_info} + COMMAND ${LCOV_PATH} --remove ${coverage_info} '*/tests/*' '*gtest*' '*gmock*' '/usr/*' --output-file ${coverage_cleaned} + COMMAND ${GENHTML_PATH} -o ${_outputname} ${coverage_cleaned} + COMMAND ${CMAKE_COMMAND} -E remove ${coverage_info} ${coverage_cleaned} + + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + COMMENT "Resetting code coverage counters to zero.\nProcessing code coverage counters and generating report." + ) + + # Show info where to find the report + ADD_CUSTOM_COMMAND(TARGET ${_targetname} POST_BUILD + COMMAND ; + COMMENT "Open ./${_outputname}/index.html in your browser to view the coverage report." + ) + +ENDFUNCTION() # SETUP_TARGET_FOR_COVERAGE + +# Param _targetname The name of new the custom make target +# Param _testrunner The name of the target which runs the tests +# Param _outputname cobertura output is generated as _outputname.xml +# Optional fourth parameter is passed as arguments to _testrunner +# Pass them in list form, e.g.: "-j;2" for -j 2 +FUNCTION(SETUP_TARGET_FOR_COVERAGE_COBERTURA _targetname _testrunner _outputname) + + IF(NOT PYTHON_EXECUTABLE) + MESSAGE(FATAL_ERROR "Python not found! Aborting...") + ENDIF() # NOT PYTHON_EXECUTABLE + + IF(NOT GCOVR_PATH) + MESSAGE(FATAL_ERROR "gcovr not found! Aborting...") + ENDIF() # NOT GCOVR_PATH + + ADD_CUSTOM_TARGET(${_targetname} + + # Run tests + ${_testrunner} ${ARGV3} + + # Running gcovr + COMMAND ${GCOVR_PATH} -x -r ${CMAKE_SOURCE_DIR} -e '${CMAKE_SOURCE_DIR}/tests/' -o ${_outputname}.xml + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + COMMENT "Running gcovr to produce Cobertura code coverage report." + ) + + # Show info where to find the report + ADD_CUSTOM_COMMAND(TARGET ${_targetname} POST_BUILD + COMMAND ; + COMMENT "Cobertura code coverage report saved in ${_outputname}.xml." + ) + +ENDFUNCTION() # SETUP_TARGET_FOR_COVERAGE_COBERTURA diff --git a/packages/CLI11/cmake/DownloadProject.CMakeLists.cmake.in b/packages/CLI11/cmake/DownloadProject.CMakeLists.cmake.in new file mode 100644 index 0000000000000000000000000000000000000000..89be4fdd4f2e0db8d22c47d4d3f8c664078c7768 --- /dev/null +++ b/packages/CLI11/cmake/DownloadProject.CMakeLists.cmake.in @@ -0,0 +1,17 @@ +# Distributed under the OSI-approved MIT License. See accompanying +# file LICENSE or https://github.com/Crascit/DownloadProject for details. + +cmake_minimum_required(VERSION 2.8.2) + +project(${DL_ARGS_PROJ}-download NONE) + +include(ExternalProject) +ExternalProject_Add(${DL_ARGS_PROJ}-download + ${DL_ARGS_UNPARSED_ARGUMENTS} + SOURCE_DIR "${DL_ARGS_SOURCE_DIR}" + BINARY_DIR "${DL_ARGS_BINARY_DIR}" + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" + TEST_COMMAND "" +) diff --git a/packages/CLI11/cmake/DownloadProject.cmake b/packages/CLI11/cmake/DownloadProject.cmake new file mode 100644 index 0000000000000000000000000000000000000000..798c74b6380c7bffe8cce235ac7d64d609a34c4d --- /dev/null +++ b/packages/CLI11/cmake/DownloadProject.cmake @@ -0,0 +1,164 @@ +# Distributed under the OSI-approved MIT License. See accompanying +# file LICENSE or https://github.com/Crascit/DownloadProject for details. +# +# MODULE: DownloadProject +# +# PROVIDES: +# download_project( PROJ projectName +# [PREFIX prefixDir] +# [DOWNLOAD_DIR downloadDir] +# [SOURCE_DIR srcDir] +# [BINARY_DIR binDir] +# [QUIET] +# ... +# ) +# +# Provides the ability to download and unpack a tarball, zip file, git repository, +# etc. at configure time (i.e. when the cmake command is run). How the downloaded +# and unpacked contents are used is up to the caller, but the motivating case is +# to download source code which can then be included directly in the build with +# add_subdirectory() after the call to download_project(). Source and build +# directories are set up with this in mind. +# +# The PROJ argument is required. The projectName value will be used to construct +# the following variables upon exit (obviously replace projectName with its actual +# value): +# +# projectName_SOURCE_DIR +# projectName_BINARY_DIR +# +# The SOURCE_DIR and BINARY_DIR arguments are optional and would not typically +# need to be provided. They can be specified if you want the downloaded source +# and build directories to be located in a specific place. The contents of +# projectName_SOURCE_DIR and projectName_BINARY_DIR will be populated with the +# locations used whether you provide SOURCE_DIR/BINARY_DIR or not. +# +# The DOWNLOAD_DIR argument does not normally need to be set. It controls the +# location of the temporary CMake build used to perform the download. +# +# The PREFIX argument can be provided to change the base location of the default +# values of DOWNLOAD_DIR, SOURCE_DIR and BINARY_DIR. If all of those three arguments +# are provided, then PREFIX will have no effect. The default value for PREFIX is +# CMAKE_BINARY_DIR. +# +# The QUIET option can be given if you do not want to show the output associated +# with downloading the specified project. +# +# In addition to the above, any other options are passed through unmodified to +# ExternalProject_Add() to perform the actual download, patch and update steps. +# The following ExternalProject_Add() options are explicitly prohibited (they +# are reserved for use by the download_project() command): +# +# CONFIGURE_COMMAND +# BUILD_COMMAND +# INSTALL_COMMAND +# TEST_COMMAND +# +# Only those ExternalProject_Add() arguments which relate to downloading, patching +# and updating of the project sources are intended to be used. Also note that at +# least one set of download-related arguments are required. +# +# If using CMake 3.2 or later, the UPDATE_DISCONNECTED option can be used to +# prevent a check at the remote end for changes every time CMake is run +# after the first successful download. See the documentation of the ExternalProject +# module for more information. It is likely you will want to use this option if it +# is available to you. Note, however, that the ExternalProject implementation contains +# bugs which result in incorrect handling of the UPDATE_DISCONNECTED option when +# using the URL download method or when specifying a SOURCE_DIR with no download +# method. Fixes for these have been created, the last of which is scheduled for +# inclusion in CMake 3.8.0. Details can be found here: +# +# https://gitlab.kitware.com/cmake/cmake/commit/bdca68388bd57f8302d3c1d83d691034b7ffa70c +# https://gitlab.kitware.com/cmake/cmake/issues/16428 +# +# If you experience build errors related to the update step, consider avoiding +# the use of UPDATE_DISCONNECTED. +# +# EXAMPLE USAGE: +# +# include(DownloadProject) +# download_project(PROJ googletest +# GIT_REPOSITORY https://github.com/google/googletest.git +# GIT_TAG master +# UPDATE_DISCONNECTED 1 +# QUIET +# ) +# +# add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR}) +# +#======================================================================================== + + +set(_DownloadProjectDir "${CMAKE_CURRENT_LIST_DIR}") + +include(CMakeParseArguments) + +function(download_project) + + set(options QUIET) + set(oneValueArgs + PROJ + PREFIX + DOWNLOAD_DIR + SOURCE_DIR + BINARY_DIR + # Prevent the following from being passed through + CONFIGURE_COMMAND + BUILD_COMMAND + INSTALL_COMMAND + TEST_COMMAND + ) + set(multiValueArgs "") + + cmake_parse_arguments(DL_ARGS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + # Hide output if requested + if (DL_ARGS_QUIET) + set(OUTPUT_QUIET "OUTPUT_QUIET") + else() + unset(OUTPUT_QUIET) + message(STATUS "Downloading/updating ${DL_ARGS_PROJ}") + endif() + + # Set up where we will put our temporary CMakeLists.txt file and also + # the base point below which the default source and binary dirs will be + if (NOT DL_ARGS_PREFIX) + set(DL_ARGS_PREFIX "${CMAKE_BINARY_DIR}") + endif() + if (NOT DL_ARGS_DOWNLOAD_DIR) + set(DL_ARGS_DOWNLOAD_DIR "${DL_ARGS_PREFIX}/${DL_ARGS_PROJ}-download") + endif() + + # Ensure the caller can know where to find the source and build directories + if (NOT DL_ARGS_SOURCE_DIR) + set(DL_ARGS_SOURCE_DIR "${DL_ARGS_PREFIX}/${DL_ARGS_PROJ}-src") + endif() + if (NOT DL_ARGS_BINARY_DIR) + set(DL_ARGS_BINARY_DIR "${DL_ARGS_PREFIX}/${DL_ARGS_PROJ}-build") + endif() + set(${DL_ARGS_PROJ}_SOURCE_DIR "${DL_ARGS_SOURCE_DIR}" PARENT_SCOPE) + set(${DL_ARGS_PROJ}_BINARY_DIR "${DL_ARGS_BINARY_DIR}" PARENT_SCOPE) + + # Create and build a separate CMake project to carry out the download. + # If we've already previously done these steps, they will not cause + # anything to be updated, so extra rebuilds of the project won't occur. + configure_file("${_DownloadProjectDir}/DownloadProject.CMakeLists.cmake.in" + "${DL_ARGS_DOWNLOAD_DIR}/CMakeLists.txt") + execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . + RESULT_VARIABLE result + ${OUTPUT_QUIET} + WORKING_DIRECTORY "${DL_ARGS_DOWNLOAD_DIR}" + ) + if(result) + message(FATAL_ERROR "CMake step for ${DL_ARGS_PROJ} failed: ${result}") + endif() + execute_process(COMMAND ${CMAKE_COMMAND} --build . + RESULT_VARIABLE result + ${OUTPUT_QUIET} + WORKING_DIRECTORY "${DL_ARGS_DOWNLOAD_DIR}" + ) + if(result) + message(FATAL_ERROR "Build step for ${DL_ARGS_PROJ} failed: ${result}") + endif() + +endfunction() diff --git a/packages/CLI11/conanfile.py b/packages/CLI11/conanfile.py new file mode 100644 index 0000000000000000000000000000000000000000..77e584f9ad7b3da1070faa52746dcc3ba401b573 --- /dev/null +++ b/packages/CLI11/conanfile.py @@ -0,0 +1,33 @@ +from conans import ConanFile, CMake +from conans.tools import load +import re + +def get_version(): + try: + content = load("include/CLI/Version.hpp") + version = re.search(r'#define CLI11_VERSION "(.*)"', content).group(1) + return version + except Exception: + return None + +class HelloConan(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" + + exports_sources = "LICENSE", "README.md", "include/*", "cmake/*", "CMakeLists.txt", "tests/*" + + def build(self): # this is not building a library, just tests + cmake = CMake(self) + cmake.definitions["CLI_EXAMPLES"] = "OFF" + cmake.definitions["CLI_SINGLE_FILE"] = "OFF" + cmake.configure() + cmake.build() + cmake.test() + cmake.install() + + def package_id(self): + self.info.header_only() diff --git a/packages/CLI11/docs/.gitignore b/packages/CLI11/docs/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..a243610e260367ef7373372b906519cdb5a58d3a --- /dev/null +++ b/packages/CLI11/docs/.gitignore @@ -0,0 +1,2 @@ +/html/* +/latex/* diff --git a/packages/CLI11/docs/Doxyfile b/packages/CLI11/docs/Doxyfile new file mode 100644 index 0000000000000000000000000000000000000000..5363a26e1f607228ee15e48dcf8e7f87a8d4aada --- /dev/null +++ b/packages/CLI11/docs/Doxyfile @@ -0,0 +1,2473 @@ +# Doxyfile 1.8.13 + +# This file describes the settings to be used by the documentation system +# doxygen (www.doxygen.org) for a project. +# +# All text after a double hash (##) is considered a comment and is placed in +# front of the TAG it is preceding. +# +# All text after a single hash (#) is considered a comment and will be ignored. +# The format is: +# TAG = value [value, ...] +# For lists, items can also be appended using: +# TAG += value [value, ...] +# Values that contain spaces should be placed between quotes (\" \"). + +#--------------------------------------------------------------------------- +# Project related configuration options +#--------------------------------------------------------------------------- + +# This tag specifies the encoding used for all characters in the config file +# that follow. The default is UTF-8 which is also the encoding used for all text +# before the first occurrence of this tag. Doxygen uses libiconv (or the iconv +# built into libc) for the transcoding. See http://www.gnu.org/software/libiconv +# for the list of possible encodings. +# The default value is: UTF-8. + +DOXYFILE_ENCODING = UTF-8 + +# The PROJECT_NAME tag is a single word (or a sequence of words surrounded by +# double-quotes, unless you are using Doxywizard) that should identify the +# project for which the documentation is generated. This name is used in the +# title of most generated pages and in a few other places. +# The default value is: My Project. + +PROJECT_NAME = "CLI11" + +# The PROJECT_NUMBER tag can be used to enter a project or revision number. This +# could be handy for archiving the generated documentation or if some version +# control system is used. + +PROJECT_NUMBER = $(TRAVIS_TAG) + +# Using the PROJECT_BRIEF tag one can provide an optional one line description +# for a project that appears at the top of each page and should give viewer a +# quick idea about the purpose of the project. Keep the description short. + +PROJECT_BRIEF = "C++11 Command Line Interface Parser" + +# With the PROJECT_LOGO tag one can specify a logo or an icon that is included +# in the documentation. The maximum height of the logo should not exceed 55 +# pixels and the maximum width should not exceed 200 pixels. Doxygen will copy +# the logo to the output directory. + +PROJECT_LOGO = + +# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) path +# into which the generated documentation will be written. If a relative path is +# entered, it will be relative to the location where doxygen was started. If +# left blank the current directory will be used. + +OUTPUT_DIRECTORY = + +# If the CREATE_SUBDIRS tag is set to YES then doxygen will create 4096 sub- +# directories (in 2 levels) under the output directory of each output format and +# will distribute the generated files over these directories. Enabling this +# option can be useful when feeding doxygen a huge amount of source files, where +# putting all generated files in the same directory would otherwise causes +# performance problems for the file system. +# The default value is: NO. + +CREATE_SUBDIRS = NO + +# If the ALLOW_UNICODE_NAMES tag is set to YES, doxygen will allow non-ASCII +# characters to appear in the names of generated files. If set to NO, non-ASCII +# characters will be escaped, for example _xE3_x81_x84 will be used for Unicode +# U+3044. +# The default value is: NO. + +ALLOW_UNICODE_NAMES = NO + +# The OUTPUT_LANGUAGE tag is used to specify the language in which all +# documentation generated by doxygen is written. Doxygen will use this +# information to generate all constant output in the proper language. +# Possible values are: Afrikaans, Arabic, Armenian, Brazilian, Catalan, Chinese, +# Chinese-Traditional, Croatian, Czech, Danish, Dutch, English (United States), +# Esperanto, Farsi (Persian), Finnish, French, German, Greek, Hungarian, +# Indonesian, Italian, Japanese, Japanese-en (Japanese with English messages), +# Korean, Korean-en (Korean with English messages), Latvian, Lithuanian, +# Macedonian, Norwegian, Persian (Farsi), Polish, Portuguese, Romanian, Russian, +# Serbian, Serbian-Cyrillic, Slovak, Slovene, Spanish, Swedish, Turkish, +# Ukrainian and Vietnamese. +# The default value is: English. + +OUTPUT_LANGUAGE = English + +# If the BRIEF_MEMBER_DESC tag is set to YES, doxygen will include brief member +# descriptions after the members that are listed in the file and class +# documentation (similar to Javadoc). Set to NO to disable this. +# The default value is: YES. + +BRIEF_MEMBER_DESC = YES + +# If the REPEAT_BRIEF tag is set to YES, doxygen will prepend the brief +# description of a member or function before the detailed description +# +# Note: If both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the +# brief descriptions will be completely suppressed. +# The default value is: YES. + +REPEAT_BRIEF = YES + +# This tag implements a quasi-intelligent brief description abbreviator that is +# used to form the text in various listings. Each string in this list, if found +# as the leading text of the brief description, will be stripped from the text +# and the result, after processing the whole list, is used as the annotated +# text. Otherwise, the brief description is used as-is. If left blank, the +# following values are used ($name is automatically replaced with the name of +# the entity):The $name class, The $name widget, The $name file, is, provides, +# specifies, contains, represents, a, an and the. + +ABBREVIATE_BRIEF = "The $name class" \ + "The $name widget" \ + "The $name file" \ + is \ + provides \ + specifies \ + contains \ + represents \ + a \ + an \ + the + +# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then +# doxygen will generate a detailed section even if there is only a brief +# description. +# The default value is: NO. + +ALWAYS_DETAILED_SEC = NO + +# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all +# inherited members of a class in the documentation of that class as if those +# members were ordinary class members. Constructors, destructors and assignment +# operators of the base classes will not be shown. +# The default value is: NO. + +INLINE_INHERITED_MEMB = NO + +# If the FULL_PATH_NAMES tag is set to YES, doxygen will prepend the full path +# before files name in the file list and in the header files. If set to NO the +# shortest path that makes the file name unique will be used +# The default value is: YES. + +FULL_PATH_NAMES = YES + +# The STRIP_FROM_PATH tag can be used to strip a user-defined part of the path. +# Stripping is only done if one of the specified strings matches the left-hand +# part of the path. The tag can be used to show relative paths in the file list. +# If left blank the directory from which doxygen is run is used as the path to +# strip. +# +# Note that you can specify absolute paths here, but also relative paths, which +# will be relative from the directory where doxygen is started. +# This tag requires that the tag FULL_PATH_NAMES is set to YES. + +STRIP_FROM_PATH = + +# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of the +# path mentioned in the documentation of a class, which tells the reader which +# header file to include in order to use a class. If left blank only the name of +# the header file containing the class definition is used. Otherwise one should +# specify the list of include paths that are normally passed to the compiler +# using the -I flag. + +STRIP_FROM_INC_PATH = + +# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter (but +# less readable) file names. This can be useful is your file systems doesn't +# support long names like on DOS, Mac, or CD-ROM. +# The default value is: NO. + +SHORT_NAMES = NO + +# If the JAVADOC_AUTOBRIEF tag is set to YES then doxygen will interpret the +# first line (until the first dot) of a Javadoc-style comment as the brief +# description. If set to NO, the Javadoc-style will behave just like regular Qt- +# style comments (thus requiring an explicit @brief command for a brief +# description.) +# The default value is: NO. + +JAVADOC_AUTOBRIEF = NO + +# If the QT_AUTOBRIEF tag is set to YES then doxygen will interpret the first +# line (until the first dot) of a Qt-style comment as the brief description. If +# set to NO, the Qt-style will behave just like regular Qt-style comments (thus +# requiring an explicit \brief command for a brief description.) +# The default value is: NO. + +QT_AUTOBRIEF = NO + +# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make doxygen treat a +# multi-line C++ special comment block (i.e. a block of //! or /// comments) as +# a brief description. This used to be the default behavior. The new default is +# to treat a multi-line C++ comment block as a detailed description. Set this +# tag to YES if you prefer the old behavior instead. +# +# Note that setting this tag to YES also means that rational rose comments are +# not recognized any more. +# The default value is: NO. + +MULTILINE_CPP_IS_BRIEF = NO + +# If the INHERIT_DOCS tag is set to YES then an undocumented member inherits the +# documentation from any documented member that it re-implements. +# The default value is: YES. + +INHERIT_DOCS = YES + +# If the SEPARATE_MEMBER_PAGES tag is set to YES then doxygen will produce a new +# page for each member. If set to NO, the documentation of a member will be part +# of the file/class/namespace that contains it. +# The default value is: NO. + +SEPARATE_MEMBER_PAGES = NO + +# The TAB_SIZE tag can be used to set the number of spaces in a tab. Doxygen +# uses this value to replace tabs by spaces in code fragments. +# Minimum value: 1, maximum value: 16, default value: 4. + +TAB_SIZE = 4 + +# This tag can be used to specify a number of aliases that act as commands in +# the documentation. An alias has the form: +# name=value +# For example adding +# "sideeffect=@par Side Effects:\n" +# will allow you to put the command \sideeffect (or @sideeffect) in the +# documentation, which will result in a user-defined paragraph with heading +# "Side Effects:". You can put \n's in the value part of an alias to insert +# newlines. + +ALIASES = + +# This tag can be used to specify a number of word-keyword mappings (TCL only). +# A mapping has the form "name=value". For example adding "class=itcl::class" +# will allow you to use the command class in the itcl::class meaning. + +TCL_SUBST = + +# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C sources +# only. Doxygen will then generate output that is more tailored for C. For +# instance, some of the names that are used will be different. The list of all +# members will be omitted, etc. +# The default value is: NO. + +OPTIMIZE_OUTPUT_FOR_C = NO + +# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java or +# Python sources only. Doxygen will then generate output that is more tailored +# for that language. For instance, namespaces will be presented as packages, +# qualified scopes will look different, etc. +# The default value is: NO. + +OPTIMIZE_OUTPUT_JAVA = NO + +# Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran +# sources. Doxygen will then generate output that is tailored for Fortran. +# The default value is: NO. + +OPTIMIZE_FOR_FORTRAN = NO + +# Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL +# sources. Doxygen will then generate output that is tailored for VHDL. +# The default value is: NO. + +OPTIMIZE_OUTPUT_VHDL = NO + +# Doxygen selects the parser to use depending on the extension of the files it +# parses. With this tag you can assign which parser to use for a given +# extension. Doxygen has a built-in mapping, but you can override or extend it +# using this tag. The format is ext=language, where ext is a file extension, and +# language is one of the parsers supported by doxygen: IDL, Java, Javascript, +# C#, C, C++, D, PHP, Objective-C, Python, Fortran (fixed format Fortran: +# FortranFixed, free formatted Fortran: FortranFree, unknown formatted Fortran: +# Fortran. In the later case the parser tries to guess whether the code is fixed +# or free formatted code, this is the default for Fortran type files), VHDL. For +# instance to make doxygen treat .inc files as Fortran files (default is PHP), +# and .f files as C (default is Fortran), use: inc=Fortran f=C. +# +# Note: For files without extension you can use no_extension as a placeholder. +# +# Note that for custom extensions you also need to set FILE_PATTERNS otherwise +# the files are not read by doxygen. + +EXTENSION_MAPPING = + +# If the MARKDOWN_SUPPORT tag is enabled then doxygen pre-processes all comments +# according to the Markdown format, which allows for more readable +# documentation. See http://daringfireball.net/projects/markdown/ for details. +# The output of markdown processing is further processed by doxygen, so you can +# mix doxygen, HTML, and XML commands with Markdown formatting. Disable only in +# case of backward compatibilities issues. +# The default value is: YES. + +MARKDOWN_SUPPORT = YES + +# When the TOC_INCLUDE_HEADINGS tag is set to a non-zero value, all headings up +# to that level are automatically included in the table of contents, even if +# they do not have an id attribute. +# Note: This feature currently applies only to Markdown headings. +# Minimum value: 0, maximum value: 99, default value: 0. +# This tag requires that the tag MARKDOWN_SUPPORT is set to YES. + +TOC_INCLUDE_HEADINGS = 0 + +# When enabled doxygen tries to link words that correspond to documented +# classes, or namespaces to their corresponding documentation. Such a link can +# be prevented in individual cases by putting a % sign in front of the word or +# globally by setting AUTOLINK_SUPPORT to NO. +# The default value is: YES. + +AUTOLINK_SUPPORT = YES + +# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want +# to include (a tag file for) the STL sources as input, then you should set this +# tag to YES in order to let doxygen match functions declarations and +# definitions whose arguments contain STL classes (e.g. func(std::string); +# versus func(std::string) {}). This also make the inheritance and collaboration +# diagrams that involve STL classes more complete and accurate. +# The default value is: NO. + +BUILTIN_STL_SUPPORT = NO + +# If you use Microsoft's C++/CLI language, you should set this option to YES to +# enable parsing support. +# The default value is: NO. + +CPP_CLI_SUPPORT = NO + +# Set the SIP_SUPPORT tag to YES if your project consists of sip (see: +# http://www.riverbankcomputing.co.uk/software/sip/intro) sources only. Doxygen +# will parse them like normal C++ but will assume all classes use public instead +# of private inheritance when no explicit protection keyword is present. +# The default value is: NO. + +SIP_SUPPORT = NO + +# For Microsoft's IDL there are propget and propput attributes to indicate +# getter and setter methods for a property. Setting this option to YES will make +# doxygen to replace the get and set methods by a property in the documentation. +# This will only work if the methods are indeed getting or setting a simple +# type. If this is not the case, or you want to show the methods anyway, you +# should set this option to NO. +# The default value is: YES. + +IDL_PROPERTY_SUPPORT = YES + +# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC +# tag is set to YES then doxygen will reuse the documentation of the first +# member in the group (if any) for the other members of the group. By default +# all members of a group must be documented explicitly. +# The default value is: NO. + +DISTRIBUTE_GROUP_DOC = NO + +# If one adds a struct or class to a group and this option is enabled, then also +# any nested class or struct is added to the same group. By default this option +# is disabled and one has to add nested compounds explicitly via \ingroup. +# The default value is: NO. + +GROUP_NESTED_COMPOUNDS = NO + +# Set the SUBGROUPING tag to YES to allow class member groups of the same type +# (for instance a group of public functions) to be put as a subgroup of that +# type (e.g. under the Public Functions section). Set it to NO to prevent +# subgrouping. Alternatively, this can be done per class using the +# \nosubgrouping command. +# The default value is: YES. + +SUBGROUPING = YES + +# When the INLINE_GROUPED_CLASSES tag is set to YES, classes, structs and unions +# are shown inside the group in which they are included (e.g. using \ingroup) +# instead of on a separate page (for HTML and Man pages) or section (for LaTeX +# and RTF). +# +# Note that this feature does not work in combination with +# SEPARATE_MEMBER_PAGES. +# The default value is: NO. + +INLINE_GROUPED_CLASSES = NO + +# When the INLINE_SIMPLE_STRUCTS tag is set to YES, structs, classes, and unions +# with only public data fields or simple typedef fields will be shown inline in +# the documentation of the scope in which they are defined (i.e. file, +# namespace, or group documentation), provided this scope is documented. If set +# to NO, structs, classes, and unions are shown on a separate page (for HTML and +# Man pages) or section (for LaTeX and RTF). +# The default value is: NO. + +INLINE_SIMPLE_STRUCTS = NO + +# When TYPEDEF_HIDES_STRUCT tag is enabled, a typedef of a struct, union, or +# enum is documented as struct, union, or enum with the name of the typedef. So +# typedef struct TypeS {} TypeT, will appear in the documentation as a struct +# with name TypeT. When disabled the typedef will appear as a member of a file, +# namespace, or class. And the struct will be named TypeS. This can typically be +# useful for C code in case the coding convention dictates that all compound +# types are typedef'ed and only the typedef is referenced, never the tag name. +# The default value is: NO. + +TYPEDEF_HIDES_STRUCT = NO + +# The size of the symbol lookup cache can be set using LOOKUP_CACHE_SIZE. This +# cache is used to resolve symbols given their name and scope. Since this can be +# an expensive process and often the same symbol appears multiple times in the +# code, doxygen keeps a cache of pre-resolved symbols. If the cache is too small +# doxygen will become slower. If the cache is too large, memory is wasted. The +# cache size is given by this formula: 2^(16+LOOKUP_CACHE_SIZE). The valid range +# is 0..9, the default is 0, corresponding to a cache size of 2^16=65536 +# symbols. At the end of a run doxygen will report the cache usage and suggest +# the optimal cache size from a speed point of view. +# Minimum value: 0, maximum value: 9, default value: 0. + +LOOKUP_CACHE_SIZE = 0 + +#--------------------------------------------------------------------------- +# Build related configuration options +#--------------------------------------------------------------------------- + +# If the EXTRACT_ALL tag is set to YES, doxygen will assume all entities in +# documentation are documented, even if no documentation was available. Private +# class members and static file members will be hidden unless the +# EXTRACT_PRIVATE respectively EXTRACT_STATIC tags are set to YES. +# Note: This will also disable the warnings about undocumented members that are +# normally produced when WARNINGS is set to YES. +# The default value is: NO. + +EXTRACT_ALL = NO + +# If the EXTRACT_PRIVATE tag is set to YES, all private members of a class will +# be included in the documentation. +# The default value is: NO. + +EXTRACT_PRIVATE = NO + +# If the EXTRACT_PACKAGE tag is set to YES, all members with package or internal +# scope will be included in the documentation. +# The default value is: NO. + +EXTRACT_PACKAGE = NO + +# If the EXTRACT_STATIC tag is set to YES, all static members of a file will be +# included in the documentation. +# The default value is: NO. + +EXTRACT_STATIC = YES + +# If the EXTRACT_LOCAL_CLASSES tag is set to YES, classes (and structs) defined +# locally in source files will be included in the documentation. If set to NO, +# only classes defined in header files are included. Does not have any effect +# for Java sources. +# The default value is: YES. + +EXTRACT_LOCAL_CLASSES = YES + +# This flag is only useful for Objective-C code. If set to YES, local methods, +# which are defined in the implementation section but not in the interface are +# included in the documentation. If set to NO, only methods in the interface are +# included. +# The default value is: NO. + +EXTRACT_LOCAL_METHODS = NO + +# If this flag is set to YES, the members of anonymous namespaces will be +# extracted and appear in the documentation as a namespace called +# 'anonymous_namespace{file}', where file will be replaced with the base name of +# the file that contains the anonymous namespace. By default anonymous namespace +# are hidden. +# The default value is: NO. + +EXTRACT_ANON_NSPACES = NO + +# If the HIDE_UNDOC_MEMBERS tag is set to YES, doxygen will hide all +# undocumented members inside documented classes or files. If set to NO these +# members will be included in the various overviews, but no documentation +# section is generated. This option has no effect if EXTRACT_ALL is enabled. +# The default value is: NO. + +HIDE_UNDOC_MEMBERS = NO + +# If the HIDE_UNDOC_CLASSES tag is set to YES, doxygen will hide all +# undocumented classes that are normally visible in the class hierarchy. If set +# to NO, these classes will be included in the various overviews. This option +# has no effect if EXTRACT_ALL is enabled. +# The default value is: NO. + +HIDE_UNDOC_CLASSES = NO + +# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, doxygen will hide all friend +# (class|struct|union) declarations. If set to NO, these declarations will be +# included in the documentation. +# The default value is: NO. + +HIDE_FRIEND_COMPOUNDS = NO + +# If the HIDE_IN_BODY_DOCS tag is set to YES, doxygen will hide any +# documentation blocks found inside the body of a function. If set to NO, these +# blocks will be appended to the function's detailed documentation block. +# The default value is: NO. + +HIDE_IN_BODY_DOCS = NO + +# The INTERNAL_DOCS tag determines if documentation that is typed after a +# \internal command is included. If the tag is set to NO then the documentation +# will be excluded. Set it to YES to include the internal documentation. +# The default value is: NO. + +INTERNAL_DOCS = NO + +# If the CASE_SENSE_NAMES tag is set to NO then doxygen will only generate file +# names in lower-case letters. If set to YES, upper-case letters are also +# allowed. This is useful if you have classes or files whose names only differ +# in case and if your file system supports case sensitive file names. Windows +# and Mac users are advised to set this option to NO. +# The default value is: system dependent. + +CASE_SENSE_NAMES = NO + +# If the HIDE_SCOPE_NAMES tag is set to NO then doxygen will show members with +# their full class and namespace scopes in the documentation. If set to YES, the +# scope will be hidden. +# The default value is: NO. + +HIDE_SCOPE_NAMES = NO + +# If the HIDE_COMPOUND_REFERENCE tag is set to NO (default) then doxygen will +# append additional text to a page's title, such as Class Reference. If set to +# YES the compound reference will be hidden. +# The default value is: NO. + +HIDE_COMPOUND_REFERENCE= NO + +# If the SHOW_INCLUDE_FILES tag is set to YES then doxygen will put a list of +# the files that are included by a file in the documentation of that file. +# The default value is: YES. + +SHOW_INCLUDE_FILES = YES + +# If the SHOW_GROUPED_MEMB_INC tag is set to YES then Doxygen will add for each +# grouped member an include statement to the documentation, telling the reader +# which file to include in order to use the member. +# The default value is: NO. + +SHOW_GROUPED_MEMB_INC = NO + +# If the FORCE_LOCAL_INCLUDES tag is set to YES then doxygen will list include +# files with double quotes in the documentation rather than with sharp brackets. +# The default value is: NO. + +FORCE_LOCAL_INCLUDES = NO + +# If the INLINE_INFO tag is set to YES then a tag [inline] is inserted in the +# documentation for inline members. +# The default value is: YES. + +INLINE_INFO = YES + +# If the SORT_MEMBER_DOCS tag is set to YES then doxygen will sort the +# (detailed) documentation of file and class members alphabetically by member +# name. If set to NO, the members will appear in declaration order. +# The default value is: YES. + +SORT_MEMBER_DOCS = YES + +# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the brief +# descriptions of file, namespace and class members alphabetically by member +# name. If set to NO, the members will appear in declaration order. Note that +# this will also influence the order of the classes in the class list. +# The default value is: NO. + +SORT_BRIEF_DOCS = NO + +# If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen will sort the +# (brief and detailed) documentation of class members so that constructors and +# destructors are listed first. If set to NO the constructors will appear in the +# respective orders defined by SORT_BRIEF_DOCS and SORT_MEMBER_DOCS. +# Note: If SORT_BRIEF_DOCS is set to NO this option is ignored for sorting brief +# member documentation. +# Note: If SORT_MEMBER_DOCS is set to NO this option is ignored for sorting +# detailed member documentation. +# The default value is: NO. + +SORT_MEMBERS_CTORS_1ST = NO + +# If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the hierarchy +# of group names into alphabetical order. If set to NO the group names will +# appear in their defined order. +# The default value is: NO. + +SORT_GROUP_NAMES = NO + +# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be sorted by +# fully-qualified names, including namespaces. If set to NO, the class list will +# be sorted only by class name, not including the namespace part. +# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES. +# Note: This option applies only to the class list, not to the alphabetical +# list. +# The default value is: NO. + +SORT_BY_SCOPE_NAME = NO + +# If the STRICT_PROTO_MATCHING option is enabled and doxygen fails to do proper +# type resolution of all parameters of a function it will reject a match between +# the prototype and the implementation of a member function even if there is +# only one candidate or it is obvious which candidate to choose by doing a +# simple string match. By disabling STRICT_PROTO_MATCHING doxygen will still +# accept a match between prototype and implementation in such cases. +# The default value is: NO. + +STRICT_PROTO_MATCHING = NO + +# The GENERATE_TODOLIST tag can be used to enable (YES) or disable (NO) the todo +# list. This list is created by putting \todo commands in the documentation. +# The default value is: YES. + +GENERATE_TODOLIST = YES + +# The GENERATE_TESTLIST tag can be used to enable (YES) or disable (NO) the test +# list. This list is created by putting \test commands in the documentation. +# The default value is: YES. + +GENERATE_TESTLIST = YES + +# The GENERATE_BUGLIST tag can be used to enable (YES) or disable (NO) the bug +# list. This list is created by putting \bug commands in the documentation. +# The default value is: YES. + +GENERATE_BUGLIST = YES + +# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or disable (NO) +# the deprecated list. This list is created by putting \deprecated commands in +# the documentation. +# The default value is: YES. + +GENERATE_DEPRECATEDLIST= YES + +# The ENABLED_SECTIONS tag can be used to enable conditional documentation +# sections, marked by \if <section_label> ... \endif and \cond <section_label> +# ... \endcond blocks. + +ENABLED_SECTIONS = + +# The MAX_INITIALIZER_LINES tag determines the maximum number of lines that the +# initial value of a variable or macro / define can have for it to appear in the +# documentation. If the initializer consists of more lines than specified here +# it will be hidden. Use a value of 0 to hide initializers completely. The +# appearance of the value of individual variables and macros / defines can be +# controlled using \showinitializer or \hideinitializer command in the +# documentation regardless of this setting. +# Minimum value: 0, maximum value: 10000, default value: 30. + +MAX_INITIALIZER_LINES = 30 + +# Set the SHOW_USED_FILES tag to NO to disable the list of files generated at +# the bottom of the documentation of classes and structs. If set to YES, the +# list will mention the files that were used to generate the documentation. +# The default value is: YES. + +SHOW_USED_FILES = YES + +# Set the SHOW_FILES tag to NO to disable the generation of the Files page. This +# will remove the Files entry from the Quick Index and from the Folder Tree View +# (if specified). +# The default value is: YES. + +SHOW_FILES = YES + +# Set the SHOW_NAMESPACES tag to NO to disable the generation of the Namespaces +# page. This will remove the Namespaces entry from the Quick Index and from the +# Folder Tree View (if specified). +# The default value is: YES. + +SHOW_NAMESPACES = YES + +# The FILE_VERSION_FILTER tag can be used to specify a program or script that +# doxygen should invoke to get the current version for each file (typically from +# the version control system). Doxygen will invoke the program by executing (via +# popen()) the command command input-file, where command is the value of the +# FILE_VERSION_FILTER tag, and input-file is the name of an input file provided +# by doxygen. Whatever the program writes to standard output is used as the file +# version. For an example see the documentation. + +FILE_VERSION_FILTER = + +# The LAYOUT_FILE tag can be used to specify a layout file which will be parsed +# by doxygen. The layout file controls the global structure of the generated +# output files in an output format independent way. To create the layout file +# that represents doxygen's defaults, run doxygen with the -l option. You can +# optionally specify a file name after the option, if omitted DoxygenLayout.xml +# will be used as the name of the layout file. +# +# Note that if you run doxygen from a directory containing a file called +# DoxygenLayout.xml, doxygen will parse it automatically even if the LAYOUT_FILE +# tag is left empty. + +LAYOUT_FILE = + +# The CITE_BIB_FILES tag can be used to specify one or more bib files containing +# the reference definitions. This must be a list of .bib files. The .bib +# extension is automatically appended if omitted. This requires the bibtex tool +# to be installed. See also http://en.wikipedia.org/wiki/BibTeX for more info. +# For LaTeX the style of the bibliography can be controlled using +# LATEX_BIB_STYLE. To use this feature you need bibtex and perl available in the +# search path. See also \cite for info how to create references. + +CITE_BIB_FILES = + +#--------------------------------------------------------------------------- +# Configuration options related to warning and progress messages +#--------------------------------------------------------------------------- + +# The QUIET tag can be used to turn on/off the messages that are generated to +# standard output by doxygen. If QUIET is set to YES this implies that the +# messages are off. +# The default value is: NO. + +QUIET = NO + +# The WARNINGS tag can be used to turn on/off the warning messages that are +# generated to standard error (stderr) by doxygen. If WARNINGS is set to YES +# this implies that the warnings are on. +# +# Tip: Turn warnings on while writing the documentation. +# The default value is: YES. + +WARNINGS = YES + +# If the WARN_IF_UNDOCUMENTED tag is set to YES then doxygen will generate +# warnings for undocumented members. If EXTRACT_ALL is set to YES then this flag +# will automatically be disabled. +# The default value is: YES. + +WARN_IF_UNDOCUMENTED = YES + +# If the WARN_IF_DOC_ERROR tag is set to YES, doxygen will generate warnings for +# potential errors in the documentation, such as not documenting some parameters +# in a documented function, or documenting parameters that don't exist or using +# markup commands wrongly. +# The default value is: YES. + +WARN_IF_DOC_ERROR = YES + +# This WARN_NO_PARAMDOC option can be enabled to get warnings for functions that +# are documented, but have no documentation for their parameters or return +# value. If set to NO, doxygen will only warn about wrong or incomplete +# parameter documentation, but not about the absence of documentation. +# The default value is: NO. + +WARN_NO_PARAMDOC = NO + +# If the WARN_AS_ERROR tag is set to YES then doxygen will immediately stop when +# a warning is encountered. +# The default value is: NO. + +WARN_AS_ERROR = NO + +# The WARN_FORMAT tag determines the format of the warning messages that doxygen +# can produce. The string should contain the $file, $line, and $text tags, which +# will be replaced by the file and line number from which the warning originated +# and the warning text. Optionally the format may contain $version, which will +# be replaced by the version of the file (if it could be obtained via +# FILE_VERSION_FILTER) +# The default value is: $file:$line: $text. + +WARN_FORMAT = "$file:$line: $text" + +# The WARN_LOGFILE tag can be used to specify a file to which warning and error +# messages should be written. If left blank the output is written to standard +# error (stderr). + +WARN_LOGFILE = + +#--------------------------------------------------------------------------- +# Configuration options related to the input files +#--------------------------------------------------------------------------- + +# The INPUT tag is used to specify the files and/or directories that contain +# documented source files. You may enter file names like myfile.cpp or +# directories like /usr/src/myproject. Separate the files or directories with +# spaces. See also FILE_PATTERNS and EXTENSION_MAPPING +# Note: If this tag is empty the current directory is searched. + +INPUT = ../include mainpage.md + +# This tag can be used to specify the character encoding of the source files +# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses +# libiconv (or the iconv built into libc) for the transcoding. See the libiconv +# documentation (see: http://www.gnu.org/software/libiconv) for the list of +# possible encodings. +# The default value is: UTF-8. + +INPUT_ENCODING = UTF-8 + +# If the value of the INPUT tag contains directories, you can use the +# FILE_PATTERNS tag to specify one or more wildcard patterns (like *.cpp and +# *.h) to filter out the source-files in the directories. +# +# Note that for custom extensions or not directly supported extensions you also +# need to set EXTENSION_MAPPING for the extension otherwise the files are not +# read by doxygen. +# +# If left blank the following patterns are tested:*.c, *.cc, *.cxx, *.cpp, +# *.c++, *.java, *.ii, *.ixx, *.ipp, *.i++, *.inl, *.idl, *.ddl, *.odl, *.h, +# *.hh, *.hxx, *.hpp, *.h++, *.cs, *.d, *.php, *.php4, *.php5, *.phtml, *.inc, +# *.m, *.markdown, *.md, *.mm, *.dox, *.py, *.pyw, *.f90, *.f95, *.f03, *.f08, +# *.f, *.for, *.tcl, *.vhd, *.vhdl, *.ucf and *.qsf. + +FILE_PATTERNS = *.c \ + *.cc \ + *.cxx \ + *.cpp \ + *.c++ \ + *.java \ + *.ii \ + *.ixx \ + *.ipp \ + *.i++ \ + *.inl \ + *.idl \ + *.ddl \ + *.odl \ + *.h \ + *.hh \ + *.hxx \ + *.hpp \ + *.h++ \ + *.cs \ + *.d \ + *.php \ + *.php4 \ + *.php5 \ + *.phtml \ + *.inc \ + *.m \ + *.markdown \ + *.md \ + *.mm \ + *.dox \ + *.py \ + *.pyw \ + *.f90 \ + *.f95 \ + *.f03 \ + *.f08 \ + *.f \ + *.for \ + *.tcl \ + *.vhd \ + *.vhdl \ + *.ucf \ + *.qsf + +# The RECURSIVE tag can be used to specify whether or not subdirectories should +# be searched for input files as well. +# The default value is: NO. + +RECURSIVE = YES + +# The EXCLUDE tag can be used to specify files and/or directories that should be +# excluded from the INPUT source files. This way you can easily exclude a +# subdirectory from a directory tree whose root is specified with the INPUT tag. +# +# Note that relative paths are relative to the directory from which doxygen is +# run. + +EXCLUDE = + +# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or +# directories that are symbolic links (a Unix file system feature) are excluded +# from the input. +# The default value is: NO. + +EXCLUDE_SYMLINKS = NO + +# If the value of the INPUT tag contains directories, you can use the +# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude +# certain files from those directories. +# +# Note that the wildcards are matched against the file with absolute path, so to +# exclude all test directories for example use the pattern */test/* + +EXCLUDE_PATTERNS = + +# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names +# (namespaces, classes, functions, etc.) that should be excluded from the +# output. The symbol name can be a fully qualified name, a word, or if the +# wildcard * is used, a substring. Examples: ANamespace, AClass, +# AClass::ANamespace, ANamespace::*Test +# +# Note that the wildcards are matched against the file with absolute path, so to +# exclude all test directories use the pattern */test/* + +EXCLUDE_SYMBOLS = + +# The EXAMPLE_PATH tag can be used to specify one or more files or directories +# that contain example code fragments that are included (see the \include +# command). + +EXAMPLE_PATH = + +# If the value of the EXAMPLE_PATH tag contains directories, you can use the +# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp and +# *.h) to filter out the source-files in the directories. If left blank all +# files are included. + +EXAMPLE_PATTERNS = * + +# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be +# searched for input files to be used with the \include or \dontinclude commands +# irrespective of the value of the RECURSIVE tag. +# The default value is: NO. + +EXAMPLE_RECURSIVE = NO + +# The IMAGE_PATH tag can be used to specify one or more files or directories +# that contain images that are to be included in the documentation (see the +# \image command). + +IMAGE_PATH = + +# The INPUT_FILTER tag can be used to specify a program that doxygen should +# invoke to filter for each input file. Doxygen will invoke the filter program +# by executing (via popen()) the command: +# +# <filter> <input-file> +# +# where <filter> is the value of the INPUT_FILTER tag, and <input-file> is the +# name of an input file. Doxygen will then use the output that the filter +# program writes to standard output. If FILTER_PATTERNS is specified, this tag +# will be ignored. +# +# Note that the filter must not add or remove lines; it is applied before the +# code is scanned, but not when the output code is generated. If lines are added +# or removed, the anchors will not be placed correctly. +# +# Note that for custom extensions or not directly supported extensions you also +# need to set EXTENSION_MAPPING for the extension otherwise the files are not +# properly processed by doxygen. + +INPUT_FILTER = + +# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern +# basis. Doxygen will compare the file name with each pattern and apply the +# filter if there is a match. The filters are a list of the form: pattern=filter +# (like *.cpp=my_cpp_filter). See INPUT_FILTER for further information on how +# filters are used. If the FILTER_PATTERNS tag is empty or if none of the +# patterns match the file name, INPUT_FILTER is applied. +# +# Note that for custom extensions or not directly supported extensions you also +# need to set EXTENSION_MAPPING for the extension otherwise the files are not +# properly processed by doxygen. + +FILTER_PATTERNS = + +# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using +# INPUT_FILTER) will also be used to filter the input files that are used for +# producing the source files to browse (i.e. when SOURCE_BROWSER is set to YES). +# The default value is: NO. + +FILTER_SOURCE_FILES = NO + +# The FILTER_SOURCE_PATTERNS tag can be used to specify source filters per file +# pattern. A pattern will override the setting for FILTER_PATTERN (if any) and +# it is also possible to disable source filtering for a specific pattern using +# *.ext= (so without naming a filter). +# This tag requires that the tag FILTER_SOURCE_FILES is set to YES. + +FILTER_SOURCE_PATTERNS = + +# If the USE_MDFILE_AS_MAINPAGE tag refers to the name of a markdown file that +# is part of the input, its contents will be placed on the main page +# (index.html). This can be useful if you have a project on for instance GitHub +# and want to reuse the introduction page also for the doxygen output. + +USE_MDFILE_AS_MAINPAGE = mainpage.md + +#--------------------------------------------------------------------------- +# Configuration options related to source browsing +#--------------------------------------------------------------------------- + +# If the SOURCE_BROWSER tag is set to YES then a list of source files will be +# generated. Documented entities will be cross-referenced with these sources. +# +# Note: To get rid of all source code in the generated output, make sure that +# also VERBATIM_HEADERS is set to NO. +# The default value is: NO. + +SOURCE_BROWSER = NO + +# Setting the INLINE_SOURCES tag to YES will include the body of functions, +# classes and enums directly into the documentation. +# The default value is: NO. + +INLINE_SOURCES = NO + +# Setting the STRIP_CODE_COMMENTS tag to YES will instruct doxygen to hide any +# special comment blocks from generated source code fragments. Normal C, C++ and +# Fortran comments will always remain visible. +# The default value is: YES. + +STRIP_CODE_COMMENTS = YES + +# If the REFERENCED_BY_RELATION tag is set to YES then for each documented +# function all documented functions referencing it will be listed. +# The default value is: NO. + +REFERENCED_BY_RELATION = NO + +# If the REFERENCES_RELATION tag is set to YES then for each documented function +# all documented entities called/used by that function will be listed. +# The default value is: NO. + +REFERENCES_RELATION = NO + +# If the REFERENCES_LINK_SOURCE tag is set to YES and SOURCE_BROWSER tag is set +# to YES then the hyperlinks from functions in REFERENCES_RELATION and +# REFERENCED_BY_RELATION lists will link to the source code. Otherwise they will +# link to the documentation. +# The default value is: YES. + +REFERENCES_LINK_SOURCE = YES + +# If SOURCE_TOOLTIPS is enabled (the default) then hovering a hyperlink in the +# source code will show a tooltip with additional information such as prototype, +# brief description and links to the definition and documentation. Since this +# will make the HTML file larger and loading of large files a bit slower, you +# can opt to disable this feature. +# The default value is: YES. +# This tag requires that the tag SOURCE_BROWSER is set to YES. + +SOURCE_TOOLTIPS = YES + +# If the USE_HTAGS tag is set to YES then the references to source code will +# point to the HTML generated by the htags(1) tool instead of doxygen built-in +# source browser. The htags tool is part of GNU's global source tagging system +# (see http://www.gnu.org/software/global/global.html). You will need version +# 4.8.6 or higher. +# +# To use it do the following: +# - Install the latest version of global +# - Enable SOURCE_BROWSER and USE_HTAGS in the config file +# - Make sure the INPUT points to the root of the source tree +# - Run doxygen as normal +# +# Doxygen will invoke htags (and that will in turn invoke gtags), so these +# tools must be available from the command line (i.e. in the search path). +# +# The result: instead of the source browser generated by doxygen, the links to +# source code will now point to the output of htags. +# The default value is: NO. +# This tag requires that the tag SOURCE_BROWSER is set to YES. + +USE_HTAGS = NO + +# If the VERBATIM_HEADERS tag is set the YES then doxygen will generate a +# verbatim copy of the header file for each class for which an include is +# specified. Set to NO to disable this. +# See also: Section \class. +# The default value is: YES. + +VERBATIM_HEADERS = YES + +#--------------------------------------------------------------------------- +# Configuration options related to the alphabetical class index +#--------------------------------------------------------------------------- + +# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index of all +# compounds will be generated. Enable this if the project contains a lot of +# classes, structs, unions or interfaces. +# The default value is: YES. + +ALPHABETICAL_INDEX = YES + +# The COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns in +# which the alphabetical index list will be split. +# Minimum value: 1, maximum value: 20, default value: 5. +# This tag requires that the tag ALPHABETICAL_INDEX is set to YES. + +COLS_IN_ALPHA_INDEX = 5 + +# In case all classes in a project start with a common prefix, all classes will +# be put under the same header in the alphabetical index. The IGNORE_PREFIX tag +# can be used to specify a prefix (or a list of prefixes) that should be ignored +# while generating the index headers. +# This tag requires that the tag ALPHABETICAL_INDEX is set to YES. + +IGNORE_PREFIX = + +#--------------------------------------------------------------------------- +# Configuration options related to the HTML output +#--------------------------------------------------------------------------- + +# If the GENERATE_HTML tag is set to YES, doxygen will generate HTML output +# The default value is: YES. + +GENERATE_HTML = YES + +# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. If a +# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of +# it. +# The default directory is: html. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_OUTPUT = html + +# The HTML_FILE_EXTENSION tag can be used to specify the file extension for each +# generated HTML page (for example: .htm, .php, .asp). +# The default value is: .html. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_FILE_EXTENSION = .html + +# The HTML_HEADER tag can be used to specify a user-defined HTML header file for +# each generated HTML page. If the tag is left blank doxygen will generate a +# standard header. +# +# To get valid HTML the header file that includes any scripts and style sheets +# that doxygen needs, which is dependent on the configuration options used (e.g. +# the setting GENERATE_TREEVIEW). It is highly recommended to start with a +# default header using +# doxygen -w html new_header.html new_footer.html new_stylesheet.css +# YourConfigFile +# and then modify the file new_header.html. See also section "Doxygen usage" +# for information on how to generate the default header that doxygen normally +# uses. +# Note: The header is subject to change so you typically have to regenerate the +# default header when upgrading to a newer version of doxygen. For a description +# of the possible markers and block names see the documentation. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_HEADER = + +# The HTML_FOOTER tag can be used to specify a user-defined HTML footer for each +# generated HTML page. If the tag is left blank doxygen will generate a standard +# footer. See HTML_HEADER for more information on how to generate a default +# footer and what special commands can be used inside the footer. See also +# section "Doxygen usage" for information on how to generate the default footer +# that doxygen normally uses. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_FOOTER = + +# The HTML_STYLESHEET tag can be used to specify a user-defined cascading style +# sheet that is used by each HTML page. It can be used to fine-tune the look of +# the HTML output. If left blank doxygen will generate a default style sheet. +# See also section "Doxygen usage" for information on how to generate the style +# sheet that doxygen normally uses. +# Note: It is recommended to use HTML_EXTRA_STYLESHEET instead of this tag, as +# it is more robust and this tag (HTML_STYLESHEET) will in the future become +# obsolete. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_STYLESHEET = + +# The HTML_EXTRA_STYLESHEET tag can be used to specify additional user-defined +# cascading style sheets that are included after the standard style sheets +# created by doxygen. Using this option one can overrule certain style aspects. +# This is preferred over using HTML_STYLESHEET since it does not replace the +# standard style sheet and is therefore more robust against future updates. +# Doxygen will copy the style sheet files to the output directory. +# Note: The order of the extra style sheet files is of importance (e.g. the last +# style sheet in the list overrules the setting of the previous ones in the +# list). For an example see the documentation. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_EXTRA_STYLESHEET = + +# The HTML_EXTRA_FILES tag can be used to specify one or more extra images or +# other source files which should be copied to the HTML output directory. Note +# that these files will be copied to the base HTML output directory. Use the +# $relpath^ marker in the HTML_HEADER and/or HTML_FOOTER files to load these +# files. In the HTML_STYLESHEET file, use the file name only. Also note that the +# files will be copied as-is; there are no commands or markers available. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_EXTRA_FILES = + +# The HTML_COLORSTYLE_HUE tag controls the color of the HTML output. Doxygen +# will adjust the colors in the style sheet and background images according to +# this color. Hue is specified as an angle on a colorwheel, see +# http://en.wikipedia.org/wiki/Hue for more information. For instance the value +# 0 represents red, 60 is yellow, 120 is green, 180 is cyan, 240 is blue, 300 +# purple, and 360 is red again. +# Minimum value: 0, maximum value: 359, default value: 220. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_COLORSTYLE_HUE = 220 + +# The HTML_COLORSTYLE_SAT tag controls the purity (or saturation) of the colors +# in the HTML output. For a value of 0 the output will use grayscales only. A +# value of 255 will produce the most vivid colors. +# Minimum value: 0, maximum value: 255, default value: 100. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_COLORSTYLE_SAT = 100 + +# The HTML_COLORSTYLE_GAMMA tag controls the gamma correction applied to the +# luminance component of the colors in the HTML output. Values below 100 +# gradually make the output lighter, whereas values above 100 make the output +# darker. The value divided by 100 is the actual gamma applied, so 80 represents +# a gamma of 0.8, The value 220 represents a gamma of 2.2, and 100 does not +# change the gamma. +# Minimum value: 40, maximum value: 240, default value: 80. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_COLORSTYLE_GAMMA = 80 + +# If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML +# page will contain the date and time when the page was generated. Setting this +# to YES can help to show when doxygen was last run and thus if the +# documentation is up to date. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_TIMESTAMP = NO + +# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML +# documentation will contain sections that can be hidden and shown after the +# page has loaded. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_DYNAMIC_SECTIONS = NO + +# With HTML_INDEX_NUM_ENTRIES one can control the preferred number of entries +# shown in the various tree structured indices initially; the user can expand +# and collapse entries dynamically later on. Doxygen will expand the tree to +# such a level that at most the specified number of entries are visible (unless +# a fully collapsed tree already exceeds this amount). So setting the number of +# entries 1 will produce a full collapsed tree by default. 0 is a special value +# representing an infinite number of entries and will result in a full expanded +# tree by default. +# Minimum value: 0, maximum value: 9999, default value: 100. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_INDEX_NUM_ENTRIES = 100 + +# If the GENERATE_DOCSET tag is set to YES, additional index files will be +# generated that can be used as input for Apple's Xcode 3 integrated development +# environment (see: http://developer.apple.com/tools/xcode/), introduced with +# OSX 10.5 (Leopard). To create a documentation set, doxygen will generate a +# Makefile in the HTML output directory. Running make will produce the docset in +# that directory and running make install will install the docset in +# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find it at +# startup. See http://developer.apple.com/tools/creatingdocsetswithdoxygen.html +# for more information. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +GENERATE_DOCSET = NO + +# This tag determines the name of the docset feed. A documentation feed provides +# an umbrella under which multiple documentation sets from a single provider +# (such as a company or product suite) can be grouped. +# The default value is: Doxygen generated docs. +# This tag requires that the tag GENERATE_DOCSET is set to YES. + +DOCSET_FEEDNAME = "Doxygen generated docs" + +# This tag specifies a string that should uniquely identify the documentation +# set bundle. This should be a reverse domain-name style string, e.g. +# com.mycompany.MyDocSet. Doxygen will append .docset to the name. +# The default value is: org.doxygen.Project. +# This tag requires that the tag GENERATE_DOCSET is set to YES. + +DOCSET_BUNDLE_ID = org.doxygen.Project + +# The DOCSET_PUBLISHER_ID tag specifies a string that should uniquely identify +# the documentation publisher. This should be a reverse domain-name style +# string, e.g. com.mycompany.MyDocSet.documentation. +# The default value is: org.doxygen.Publisher. +# This tag requires that the tag GENERATE_DOCSET is set to YES. + +DOCSET_PUBLISHER_ID = org.doxygen.Publisher + +# The DOCSET_PUBLISHER_NAME tag identifies the documentation publisher. +# The default value is: Publisher. +# This tag requires that the tag GENERATE_DOCSET is set to YES. + +DOCSET_PUBLISHER_NAME = Publisher + +# If the GENERATE_HTMLHELP tag is set to YES then doxygen generates three +# additional HTML index files: index.hhp, index.hhc, and index.hhk. The +# index.hhp is a project file that can be read by Microsoft's HTML Help Workshop +# (see: http://www.microsoft.com/en-us/download/details.aspx?id=21138) on +# Windows. +# +# The HTML Help Workshop contains a compiler that can convert all HTML output +# generated by doxygen into a single compiled HTML file (.chm). Compiled HTML +# files are now used as the Windows 98 help format, and will replace the old +# Windows help format (.hlp) on all Windows platforms in the future. Compressed +# HTML files also contain an index, a table of contents, and you can search for +# words in the documentation. The HTML workshop also contains a viewer for +# compressed HTML files. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +GENERATE_HTMLHELP = NO + +# The CHM_FILE tag can be used to specify the file name of the resulting .chm +# file. You can add a path in front of the file if the result should not be +# written to the html output directory. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +CHM_FILE = + +# The HHC_LOCATION tag can be used to specify the location (absolute path +# including file name) of the HTML help compiler (hhc.exe). If non-empty, +# doxygen will try to run the HTML help compiler on the generated index.hhp. +# The file has to be specified with full path. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +HHC_LOCATION = + +# The GENERATE_CHI flag controls if a separate .chi index file is generated +# (YES) or that it should be included in the master .chm file (NO). +# The default value is: NO. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +GENERATE_CHI = NO + +# The CHM_INDEX_ENCODING is used to encode HtmlHelp index (hhk), content (hhc) +# and project file content. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +CHM_INDEX_ENCODING = + +# The BINARY_TOC flag controls whether a binary table of contents is generated +# (YES) or a normal table of contents (NO) in the .chm file. Furthermore it +# enables the Previous and Next buttons. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +BINARY_TOC = NO + +# The TOC_EXPAND flag can be set to YES to add extra items for group members to +# the table of contents of the HTML help documentation and to the tree view. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +TOC_EXPAND = NO + +# If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and +# QHP_VIRTUAL_FOLDER are set, an additional index file will be generated that +# can be used as input for Qt's qhelpgenerator to generate a Qt Compressed Help +# (.qch) of the generated HTML documentation. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +GENERATE_QHP = NO + +# If the QHG_LOCATION tag is specified, the QCH_FILE tag can be used to specify +# the file name of the resulting .qch file. The path specified is relative to +# the HTML output folder. +# This tag requires that the tag GENERATE_QHP is set to YES. + +QCH_FILE = + +# The QHP_NAMESPACE tag specifies the namespace to use when generating Qt Help +# Project output. For more information please see Qt Help Project / Namespace +# (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#namespace). +# The default value is: org.doxygen.Project. +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHP_NAMESPACE = org.doxygen.Project + +# The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating Qt +# Help Project output. For more information please see Qt Help Project / Virtual +# Folders (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#virtual- +# folders). +# The default value is: doc. +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHP_VIRTUAL_FOLDER = doc + +# If the QHP_CUST_FILTER_NAME tag is set, it specifies the name of a custom +# filter to add. For more information please see Qt Help Project / Custom +# Filters (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom- +# filters). +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHP_CUST_FILTER_NAME = + +# The QHP_CUST_FILTER_ATTRS tag specifies the list of the attributes of the +# custom filter to add. For more information please see Qt Help Project / Custom +# Filters (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom- +# filters). +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHP_CUST_FILTER_ATTRS = + +# The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this +# project's filter section matches. Qt Help Project / Filter Attributes (see: +# http://qt-project.org/doc/qt-4.8/qthelpproject.html#filter-attributes). +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHP_SECT_FILTER_ATTRS = + +# The QHG_LOCATION tag can be used to specify the location of Qt's +# qhelpgenerator. If non-empty doxygen will try to run qhelpgenerator on the +# generated .qhp file. +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHG_LOCATION = + +# If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files will be +# generated, together with the HTML files, they form an Eclipse help plugin. To +# install this plugin and make it available under the help contents menu in +# Eclipse, the contents of the directory containing the HTML and XML files needs +# to be copied into the plugins directory of eclipse. The name of the directory +# within the plugins directory should be the same as the ECLIPSE_DOC_ID value. +# After copying Eclipse needs to be restarted before the help appears. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +GENERATE_ECLIPSEHELP = NO + +# A unique identifier for the Eclipse help plugin. When installing the plugin +# the directory name containing the HTML and XML files should also have this +# name. Each documentation set should have its own identifier. +# The default value is: org.doxygen.Project. +# This tag requires that the tag GENERATE_ECLIPSEHELP is set to YES. + +ECLIPSE_DOC_ID = org.doxygen.Project + +# If you want full control over the layout of the generated HTML pages it might +# be necessary to disable the index and replace it with your own. The +# DISABLE_INDEX tag can be used to turn on/off the condensed index (tabs) at top +# of each HTML page. A value of NO enables the index and the value YES disables +# it. Since the tabs in the index contain the same information as the navigation +# tree, you can set this option to YES if you also set GENERATE_TREEVIEW to YES. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +DISABLE_INDEX = NO + +# The GENERATE_TREEVIEW tag is used to specify whether a tree-like index +# structure should be generated to display hierarchical information. If the tag +# value is set to YES, a side panel will be generated containing a tree-like +# index structure (just like the one that is generated for HTML Help). For this +# to work a browser that supports JavaScript, DHTML, CSS and frames is required +# (i.e. any modern browser). Windows users are probably better off using the +# HTML help feature. Via custom style sheets (see HTML_EXTRA_STYLESHEET) one can +# further fine-tune the look of the index. As an example, the default style +# sheet generated by doxygen has an example that shows how to put an image at +# the root of the tree instead of the PROJECT_NAME. Since the tree basically has +# the same information as the tab index, you could consider setting +# DISABLE_INDEX to YES when enabling this option. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +GENERATE_TREEVIEW = NO + +# The ENUM_VALUES_PER_LINE tag can be used to set the number of enum values that +# doxygen will group on one line in the generated HTML documentation. +# +# Note that a value of 0 will completely suppress the enum values from appearing +# in the overview section. +# Minimum value: 0, maximum value: 20, default value: 4. +# This tag requires that the tag GENERATE_HTML is set to YES. + +ENUM_VALUES_PER_LINE = 4 + +# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be used +# to set the initial width (in pixels) of the frame in which the tree is shown. +# Minimum value: 0, maximum value: 1500, default value: 250. +# This tag requires that the tag GENERATE_HTML is set to YES. + +TREEVIEW_WIDTH = 250 + +# If the EXT_LINKS_IN_WINDOW option is set to YES, doxygen will open links to +# external symbols imported via tag files in a separate window. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +EXT_LINKS_IN_WINDOW = NO + +# Use this tag to change the font size of LaTeX formulas included as images in +# the HTML documentation. When you change the font size after a successful +# doxygen run you need to manually remove any form_*.png images from the HTML +# output directory to force them to be regenerated. +# Minimum value: 8, maximum value: 50, default value: 10. +# This tag requires that the tag GENERATE_HTML is set to YES. + +FORMULA_FONTSIZE = 10 + +# Use the FORMULA_TRANPARENT tag to determine whether or not the images +# generated for formulas are transparent PNGs. Transparent PNGs are not +# supported properly for IE 6.0, but are supported on all modern browsers. +# +# Note that when changing this option you need to delete any form_*.png files in +# the HTML output directory before the changes have effect. +# The default value is: YES. +# This tag requires that the tag GENERATE_HTML is set to YES. + +FORMULA_TRANSPARENT = YES + +# Enable the USE_MATHJAX option to render LaTeX formulas using MathJax (see +# http://www.mathjax.org) which uses client side Javascript for the rendering +# instead of using pre-rendered bitmaps. Use this if you do not have LaTeX +# installed or if you want to formulas look prettier in the HTML output. When +# enabled you may also need to install MathJax separately and configure the path +# to it using the MATHJAX_RELPATH option. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +USE_MATHJAX = NO + +# When MathJax is enabled you can set the default output format to be used for +# the MathJax output. See the MathJax site (see: +# http://docs.mathjax.org/en/latest/output.html) for more details. +# Possible values are: HTML-CSS (which is slower, but has the best +# compatibility), NativeMML (i.e. MathML) and SVG. +# The default value is: HTML-CSS. +# This tag requires that the tag USE_MATHJAX is set to YES. + +MATHJAX_FORMAT = HTML-CSS + +# When MathJax is enabled you need to specify the location relative to the HTML +# output directory using the MATHJAX_RELPATH option. The destination directory +# should contain the MathJax.js script. For instance, if the mathjax directory +# is located at the same level as the HTML output directory, then +# MATHJAX_RELPATH should be ../mathjax. The default value points to the MathJax +# Content Delivery Network so you can quickly see the result without installing +# MathJax. However, it is strongly recommended to install a local copy of +# MathJax from http://www.mathjax.org before deployment. +# The default value is: http://cdn.mathjax.org/mathjax/latest. +# This tag requires that the tag USE_MATHJAX is set to YES. + +MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest + +# The MATHJAX_EXTENSIONS tag can be used to specify one or more MathJax +# extension names that should be enabled during MathJax rendering. For example +# MATHJAX_EXTENSIONS = TeX/AMSmath TeX/AMSsymbols +# This tag requires that the tag USE_MATHJAX is set to YES. + +MATHJAX_EXTENSIONS = + +# The MATHJAX_CODEFILE tag can be used to specify a file with javascript pieces +# of code that will be used on startup of the MathJax code. See the MathJax site +# (see: http://docs.mathjax.org/en/latest/output.html) for more details. For an +# example see the documentation. +# This tag requires that the tag USE_MATHJAX is set to YES. + +MATHJAX_CODEFILE = + +# When the SEARCHENGINE tag is enabled doxygen will generate a search box for +# the HTML output. The underlying search engine uses javascript and DHTML and +# should work on any modern browser. Note that when using HTML help +# (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets (GENERATE_DOCSET) +# there is already a search function so this one should typically be disabled. +# For large projects the javascript based search engine can be slow, then +# enabling SERVER_BASED_SEARCH may provide a better solution. It is possible to +# search using the keyboard; to jump to the search box use <access key> + S +# (what the <access key> is depends on the OS and browser, but it is typically +# <CTRL>, <ALT>/<option>, or both). Inside the search box use the <cursor down +# key> to jump into the search results window, the results can be navigated +# using the <cursor keys>. Press <Enter> to select an item or <escape> to cancel +# the search. The filter options can be selected when the cursor is inside the +# search box by pressing <Shift>+<cursor down>. Also here use the <cursor keys> +# to select a filter and <Enter> or <escape> to activate or cancel the filter +# option. +# The default value is: YES. +# This tag requires that the tag GENERATE_HTML is set to YES. + +SEARCHENGINE = YES + +# When the SERVER_BASED_SEARCH tag is enabled the search engine will be +# implemented using a web server instead of a web client using Javascript. There +# are two flavors of web server based searching depending on the EXTERNAL_SEARCH +# setting. When disabled, doxygen will generate a PHP script for searching and +# an index file used by the script. When EXTERNAL_SEARCH is enabled the indexing +# and searching needs to be provided by external tools. See the section +# "External Indexing and Searching" for details. +# The default value is: NO. +# This tag requires that the tag SEARCHENGINE is set to YES. + +SERVER_BASED_SEARCH = NO + +# When EXTERNAL_SEARCH tag is enabled doxygen will no longer generate the PHP +# script for searching. Instead the search results are written to an XML file +# which needs to be processed by an external indexer. Doxygen will invoke an +# external search engine pointed to by the SEARCHENGINE_URL option to obtain the +# search results. +# +# Doxygen ships with an example indexer (doxyindexer) and search engine +# (doxysearch.cgi) which are based on the open source search engine library +# Xapian (see: http://xapian.org/). +# +# See the section "External Indexing and Searching" for details. +# The default value is: NO. +# This tag requires that the tag SEARCHENGINE is set to YES. + +EXTERNAL_SEARCH = NO + +# The SEARCHENGINE_URL should point to a search engine hosted by a web server +# which will return the search results when EXTERNAL_SEARCH is enabled. +# +# Doxygen ships with an example indexer (doxyindexer) and search engine +# (doxysearch.cgi) which are based on the open source search engine library +# Xapian (see: http://xapian.org/). See the section "External Indexing and +# Searching" for details. +# This tag requires that the tag SEARCHENGINE is set to YES. + +SEARCHENGINE_URL = + +# When SERVER_BASED_SEARCH and EXTERNAL_SEARCH are both enabled the unindexed +# search data is written to a file for indexing by an external tool. With the +# SEARCHDATA_FILE tag the name of this file can be specified. +# The default file is: searchdata.xml. +# This tag requires that the tag SEARCHENGINE is set to YES. + +SEARCHDATA_FILE = searchdata.xml + +# When SERVER_BASED_SEARCH and EXTERNAL_SEARCH are both enabled the +# EXTERNAL_SEARCH_ID tag can be used as an identifier for the project. This is +# useful in combination with EXTRA_SEARCH_MAPPINGS to search through multiple +# projects and redirect the results back to the right project. +# This tag requires that the tag SEARCHENGINE is set to YES. + +EXTERNAL_SEARCH_ID = + +# The EXTRA_SEARCH_MAPPINGS tag can be used to enable searching through doxygen +# projects other than the one defined by this configuration file, but that are +# all added to the same external search index. Each project needs to have a +# unique id set via EXTERNAL_SEARCH_ID. The search mapping then maps the id of +# to a relative location where the documentation can be found. The format is: +# EXTRA_SEARCH_MAPPINGS = tagname1=loc1 tagname2=loc2 ... +# This tag requires that the tag SEARCHENGINE is set to YES. + +EXTRA_SEARCH_MAPPINGS = + +#--------------------------------------------------------------------------- +# Configuration options related to the LaTeX output +#--------------------------------------------------------------------------- + +# If the GENERATE_LATEX tag is set to YES, doxygen will generate LaTeX output. +# The default value is: YES. + +GENERATE_LATEX = NO + +# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. If a +# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of +# it. +# The default directory is: latex. +# This tag requires that the tag GENERATE_LATEX is set to YES. + +LATEX_OUTPUT = latex + +# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be +# invoked. +# +# Note that when enabling USE_PDFLATEX this option is only used for generating +# bitmaps for formulas in the HTML output, but not in the Makefile that is +# written to the output directory. +# The default file is: latex. +# This tag requires that the tag GENERATE_LATEX is set to YES. + +LATEX_CMD_NAME = latex + +# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to generate +# index for LaTeX. +# The default file is: makeindex. +# This tag requires that the tag GENERATE_LATEX is set to YES. + +MAKEINDEX_CMD_NAME = makeindex + +# If the COMPACT_LATEX tag is set to YES, doxygen generates more compact LaTeX +# documents. This may be useful for small projects and may help to save some +# trees in general. +# The default value is: NO. +# This tag requires that the tag GENERATE_LATEX is set to YES. + +COMPACT_LATEX = NO + +# The PAPER_TYPE tag can be used to set the paper type that is used by the +# printer. +# Possible values are: a4 (210 x 297 mm), letter (8.5 x 11 inches), legal (8.5 x +# 14 inches) and executive (7.25 x 10.5 inches). +# The default value is: a4. +# This tag requires that the tag GENERATE_LATEX is set to YES. + +PAPER_TYPE = a4 + +# The EXTRA_PACKAGES tag can be used to specify one or more LaTeX package names +# that should be included in the LaTeX output. The package can be specified just +# by its name or with the correct syntax as to be used with the LaTeX +# \usepackage command. To get the times font for instance you can specify : +# EXTRA_PACKAGES=times or EXTRA_PACKAGES={times} +# To use the option intlimits with the amsmath package you can specify: +# EXTRA_PACKAGES=[intlimits]{amsmath} +# If left blank no extra packages will be included. +# This tag requires that the tag GENERATE_LATEX is set to YES. + +EXTRA_PACKAGES = + +# The LATEX_HEADER tag can be used to specify a personal LaTeX header for the +# generated LaTeX document. The header should contain everything until the first +# chapter. If it is left blank doxygen will generate a standard header. See +# section "Doxygen usage" for information on how to let doxygen write the +# default header to a separate file. +# +# Note: Only use a user-defined header if you know what you are doing! The +# following commands have a special meaning inside the header: $title, +# $datetime, $date, $doxygenversion, $projectname, $projectnumber, +# $projectbrief, $projectlogo. Doxygen will replace $title with the empty +# string, for the replacement values of the other commands the user is referred +# to HTML_HEADER. +# This tag requires that the tag GENERATE_LATEX is set to YES. + +LATEX_HEADER = + +# The LATEX_FOOTER tag can be used to specify a personal LaTeX footer for the +# generated LaTeX document. The footer should contain everything after the last +# chapter. If it is left blank doxygen will generate a standard footer. See +# LATEX_HEADER for more information on how to generate a default footer and what +# special commands can be used inside the footer. +# +# Note: Only use a user-defined footer if you know what you are doing! +# This tag requires that the tag GENERATE_LATEX is set to YES. + +LATEX_FOOTER = + +# The LATEX_EXTRA_STYLESHEET tag can be used to specify additional user-defined +# LaTeX style sheets that are included after the standard style sheets created +# by doxygen. Using this option one can overrule certain style aspects. Doxygen +# will copy the style sheet files to the output directory. +# Note: The order of the extra style sheet files is of importance (e.g. the last +# style sheet in the list overrules the setting of the previous ones in the +# list). +# This tag requires that the tag GENERATE_LATEX is set to YES. + +LATEX_EXTRA_STYLESHEET = + +# The LATEX_EXTRA_FILES tag can be used to specify one or more extra images or +# other source files which should be copied to the LATEX_OUTPUT output +# directory. Note that the files will be copied as-is; there are no commands or +# markers available. +# This tag requires that the tag GENERATE_LATEX is set to YES. + +LATEX_EXTRA_FILES = + +# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated is +# prepared for conversion to PDF (using ps2pdf or pdflatex). The PDF file will +# contain links (just like the HTML output) instead of page references. This +# makes the output suitable for online browsing using a PDF viewer. +# The default value is: YES. +# This tag requires that the tag GENERATE_LATEX is set to YES. + +PDF_HYPERLINKS = YES + +# If the USE_PDFLATEX tag is set to YES, doxygen will use pdflatex to generate +# the PDF file directly from the LaTeX files. Set this option to YES, to get a +# higher quality PDF documentation. +# The default value is: YES. +# This tag requires that the tag GENERATE_LATEX is set to YES. + +USE_PDFLATEX = YES + +# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \batchmode +# command to the generated LaTeX files. This will instruct LaTeX to keep running +# if errors occur, instead of asking the user for help. This option is also used +# when generating formulas in HTML. +# The default value is: NO. +# This tag requires that the tag GENERATE_LATEX is set to YES. + +LATEX_BATCHMODE = NO + +# If the LATEX_HIDE_INDICES tag is set to YES then doxygen will not include the +# index chapters (such as File Index, Compound Index, etc.) in the output. +# The default value is: NO. +# This tag requires that the tag GENERATE_LATEX is set to YES. + +LATEX_HIDE_INDICES = NO + +# If the LATEX_SOURCE_CODE tag is set to YES then doxygen will include source +# code with syntax highlighting in the LaTeX output. +# +# Note that which sources are shown also depends on other settings such as +# SOURCE_BROWSER. +# The default value is: NO. +# This tag requires that the tag GENERATE_LATEX is set to YES. + +LATEX_SOURCE_CODE = NO + +# The LATEX_BIB_STYLE tag can be used to specify the style to use for the +# bibliography, e.g. plainnat, or ieeetr. See +# http://en.wikipedia.org/wiki/BibTeX and \cite for more info. +# The default value is: plain. +# This tag requires that the tag GENERATE_LATEX is set to YES. + +LATEX_BIB_STYLE = plain + +# If the LATEX_TIMESTAMP tag is set to YES then the footer of each generated +# page will contain the date and time when the page was generated. Setting this +# to NO can help when comparing the output of multiple runs. +# The default value is: NO. +# This tag requires that the tag GENERATE_LATEX is set to YES. + +LATEX_TIMESTAMP = NO + +#--------------------------------------------------------------------------- +# Configuration options related to the RTF output +#--------------------------------------------------------------------------- + +# If the GENERATE_RTF tag is set to YES, doxygen will generate RTF output. The +# RTF output is optimized for Word 97 and may not look too pretty with other RTF +# readers/editors. +# The default value is: NO. + +GENERATE_RTF = NO + +# The RTF_OUTPUT tag is used to specify where the RTF docs will be put. If a +# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of +# it. +# The default directory is: rtf. +# This tag requires that the tag GENERATE_RTF is set to YES. + +RTF_OUTPUT = rtf + +# If the COMPACT_RTF tag is set to YES, doxygen generates more compact RTF +# documents. This may be useful for small projects and may help to save some +# trees in general. +# The default value is: NO. +# This tag requires that the tag GENERATE_RTF is set to YES. + +COMPACT_RTF = NO + +# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated will +# contain hyperlink fields. The RTF file will contain links (just like the HTML +# output) instead of page references. This makes the output suitable for online +# browsing using Word or some other Word compatible readers that support those +# fields. +# +# Note: WordPad (write) and others do not support links. +# The default value is: NO. +# This tag requires that the tag GENERATE_RTF is set to YES. + +RTF_HYPERLINKS = NO + +# Load stylesheet definitions from file. Syntax is similar to doxygen's config +# file, i.e. a series of assignments. You only have to provide replacements, +# missing definitions are set to their default value. +# +# See also section "Doxygen usage" for information on how to generate the +# default style sheet that doxygen normally uses. +# This tag requires that the tag GENERATE_RTF is set to YES. + +RTF_STYLESHEET_FILE = + +# Set optional variables used in the generation of an RTF document. Syntax is +# similar to doxygen's config file. A template extensions file can be generated +# using doxygen -e rtf extensionFile. +# This tag requires that the tag GENERATE_RTF is set to YES. + +RTF_EXTENSIONS_FILE = + +# If the RTF_SOURCE_CODE tag is set to YES then doxygen will include source code +# with syntax highlighting in the RTF output. +# +# Note that which sources are shown also depends on other settings such as +# SOURCE_BROWSER. +# The default value is: NO. +# This tag requires that the tag GENERATE_RTF is set to YES. + +RTF_SOURCE_CODE = NO + +#--------------------------------------------------------------------------- +# Configuration options related to the man page output +#--------------------------------------------------------------------------- + +# If the GENERATE_MAN tag is set to YES, doxygen will generate man pages for +# classes and files. +# The default value is: NO. + +GENERATE_MAN = NO + +# The MAN_OUTPUT tag is used to specify where the man pages will be put. If a +# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of +# it. A directory man3 will be created inside the directory specified by +# MAN_OUTPUT. +# The default directory is: man. +# This tag requires that the tag GENERATE_MAN is set to YES. + +MAN_OUTPUT = man + +# The MAN_EXTENSION tag determines the extension that is added to the generated +# man pages. In case the manual section does not start with a number, the number +# 3 is prepended. The dot (.) at the beginning of the MAN_EXTENSION tag is +# optional. +# The default value is: .3. +# This tag requires that the tag GENERATE_MAN is set to YES. + +MAN_EXTENSION = .3 + +# The MAN_SUBDIR tag determines the name of the directory created within +# MAN_OUTPUT in which the man pages are placed. If defaults to man followed by +# MAN_EXTENSION with the initial . removed. +# This tag requires that the tag GENERATE_MAN is set to YES. + +MAN_SUBDIR = + +# If the MAN_LINKS tag is set to YES and doxygen generates man output, then it +# will generate one additional man file for each entity documented in the real +# man page(s). These additional files only source the real man page, but without +# them the man command would be unable to find the correct page. +# The default value is: NO. +# This tag requires that the tag GENERATE_MAN is set to YES. + +MAN_LINKS = NO + +#--------------------------------------------------------------------------- +# Configuration options related to the XML output +#--------------------------------------------------------------------------- + +# If the GENERATE_XML tag is set to YES, doxygen will generate an XML file that +# captures the structure of the code including all documentation. +# The default value is: NO. + +GENERATE_XML = NO + +# The XML_OUTPUT tag is used to specify where the XML pages will be put. If a +# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of +# it. +# The default directory is: xml. +# This tag requires that the tag GENERATE_XML is set to YES. + +XML_OUTPUT = xml + +# If the XML_PROGRAMLISTING tag is set to YES, doxygen will dump the program +# listings (including syntax highlighting and cross-referencing information) to +# the XML output. Note that enabling this will significantly increase the size +# of the XML output. +# The default value is: YES. +# This tag requires that the tag GENERATE_XML is set to YES. + +XML_PROGRAMLISTING = YES + +#--------------------------------------------------------------------------- +# Configuration options related to the DOCBOOK output +#--------------------------------------------------------------------------- + +# If the GENERATE_DOCBOOK tag is set to YES, doxygen will generate Docbook files +# that can be used to generate PDF. +# The default value is: NO. + +GENERATE_DOCBOOK = NO + +# The DOCBOOK_OUTPUT tag is used to specify where the Docbook pages will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be put in +# front of it. +# The default directory is: docbook. +# This tag requires that the tag GENERATE_DOCBOOK is set to YES. + +DOCBOOK_OUTPUT = docbook + +# If the DOCBOOK_PROGRAMLISTING tag is set to YES, doxygen will include the +# program listings (including syntax highlighting and cross-referencing +# information) to the DOCBOOK output. Note that enabling this will significantly +# increase the size of the DOCBOOK output. +# The default value is: NO. +# This tag requires that the tag GENERATE_DOCBOOK is set to YES. + +DOCBOOK_PROGRAMLISTING = NO + +#--------------------------------------------------------------------------- +# Configuration options for the AutoGen Definitions output +#--------------------------------------------------------------------------- + +# If the GENERATE_AUTOGEN_DEF tag is set to YES, doxygen will generate an +# AutoGen Definitions (see http://autogen.sf.net) file that captures the +# structure of the code including all documentation. Note that this feature is +# still experimental and incomplete at the moment. +# The default value is: NO. + +GENERATE_AUTOGEN_DEF = NO + +#--------------------------------------------------------------------------- +# Configuration options related to the Perl module output +#--------------------------------------------------------------------------- + +# If the GENERATE_PERLMOD tag is set to YES, doxygen will generate a Perl module +# file that captures the structure of the code including all documentation. +# +# Note that this feature is still experimental and incomplete at the moment. +# The default value is: NO. + +GENERATE_PERLMOD = NO + +# If the PERLMOD_LATEX tag is set to YES, doxygen will generate the necessary +# Makefile rules, Perl scripts and LaTeX code to be able to generate PDF and DVI +# output from the Perl module output. +# The default value is: NO. +# This tag requires that the tag GENERATE_PERLMOD is set to YES. + +PERLMOD_LATEX = NO + +# If the PERLMOD_PRETTY tag is set to YES, the Perl module output will be nicely +# formatted so it can be parsed by a human reader. This is useful if you want to +# understand what is going on. On the other hand, if this tag is set to NO, the +# size of the Perl module output will be much smaller and Perl will parse it +# just the same. +# The default value is: YES. +# This tag requires that the tag GENERATE_PERLMOD is set to YES. + +PERLMOD_PRETTY = YES + +# The names of the make variables in the generated doxyrules.make file are +# prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX. This is useful +# so different doxyrules.make files included by the same Makefile don't +# overwrite each other's variables. +# This tag requires that the tag GENERATE_PERLMOD is set to YES. + +PERLMOD_MAKEVAR_PREFIX = + +#--------------------------------------------------------------------------- +# Configuration options related to the preprocessor +#--------------------------------------------------------------------------- + +# If the ENABLE_PREPROCESSING tag is set to YES, doxygen will evaluate all +# C-preprocessor directives found in the sources and include files. +# The default value is: YES. + +ENABLE_PREPROCESSING = YES + +# If the MACRO_EXPANSION tag is set to YES, doxygen will expand all macro names +# in the source code. If set to NO, only conditional compilation will be +# performed. Macro expansion can be done in a controlled way by setting +# EXPAND_ONLY_PREDEF to YES. +# The default value is: NO. +# This tag requires that the tag ENABLE_PREPROCESSING is set to YES. + +MACRO_EXPANSION = NO + +# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES then +# the macro expansion is limited to the macros specified with the PREDEFINED and +# EXPAND_AS_DEFINED tags. +# The default value is: NO. +# This tag requires that the tag ENABLE_PREPROCESSING is set to YES. + +EXPAND_ONLY_PREDEF = NO + +# If the SEARCH_INCLUDES tag is set to YES, the include files in the +# INCLUDE_PATH will be searched if a #include is found. +# The default value is: YES. +# This tag requires that the tag ENABLE_PREPROCESSING is set to YES. + +SEARCH_INCLUDES = YES + +# The INCLUDE_PATH tag can be used to specify one or more directories that +# contain include files that are not input files but should be processed by the +# preprocessor. +# This tag requires that the tag SEARCH_INCLUDES is set to YES. + +INCLUDE_PATH = + +# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard +# patterns (like *.h and *.hpp) to filter out the header-files in the +# directories. If left blank, the patterns specified with FILE_PATTERNS will be +# used. +# This tag requires that the tag ENABLE_PREPROCESSING is set to YES. + +INCLUDE_FILE_PATTERNS = + +# The PREDEFINED tag can be used to specify one or more macro names that are +# defined before the preprocessor is started (similar to the -D option of e.g. +# gcc). The argument of the tag is a list of macros of the form: name or +# name=definition (no spaces). If the definition and the "=" are omitted, "=1" +# is assumed. To prevent a macro definition from being undefined via #undef or +# recursively expanded use the := operator instead of the = operator. +# This tag requires that the tag ENABLE_PREPROCESSING is set to YES. + +PREDEFINED = + +# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this +# tag can be used to specify a list of macro names that should be expanded. The +# macro definition that is found in the sources will be used. Use the PREDEFINED +# tag if you want to use a different macro definition that overrules the +# definition found in the source code. +# This tag requires that the tag ENABLE_PREPROCESSING is set to YES. + +EXPAND_AS_DEFINED = + +# If the SKIP_FUNCTION_MACROS tag is set to YES then doxygen's preprocessor will +# remove all references to function-like macros that are alone on a line, have +# an all uppercase name, and do not end with a semicolon. Such function macros +# are typically used for boiler-plate code, and will confuse the parser if not +# removed. +# The default value is: YES. +# This tag requires that the tag ENABLE_PREPROCESSING is set to YES. + +SKIP_FUNCTION_MACROS = YES + +#--------------------------------------------------------------------------- +# Configuration options related to external references +#--------------------------------------------------------------------------- + +# The TAGFILES tag can be used to specify one or more tag files. For each tag +# file the location of the external documentation should be added. The format of +# a tag file without this location is as follows: +# TAGFILES = file1 file2 ... +# Adding location for the tag files is done as follows: +# TAGFILES = file1=loc1 "file2 = loc2" ... +# where loc1 and loc2 can be relative or absolute paths or URLs. See the +# section "Linking to external documentation" for more information about the use +# of tag files. +# Note: Each tag file must have a unique name (where the name does NOT include +# the path). If a tag file is not located in the directory in which doxygen is +# run, you must also specify the path to the tagfile here. + +TAGFILES = + +# When a file name is specified after GENERATE_TAGFILE, doxygen will create a +# tag file that is based on the input files it reads. See section "Linking to +# external documentation" for more information about the usage of tag files. + +GENERATE_TAGFILE = + +# If the ALLEXTERNALS tag is set to YES, all external class will be listed in +# the class index. If set to NO, only the inherited external classes will be +# listed. +# The default value is: NO. + +ALLEXTERNALS = NO + +# If the EXTERNAL_GROUPS tag is set to YES, all external groups will be listed +# in the modules index. If set to NO, only the current project's groups will be +# listed. +# The default value is: YES. + +EXTERNAL_GROUPS = YES + +# If the EXTERNAL_PAGES tag is set to YES, all external pages will be listed in +# the related pages index. If set to NO, only the current project's pages will +# be listed. +# The default value is: YES. + +EXTERNAL_PAGES = YES + +# The PERL_PATH should be the absolute path and name of the perl script +# interpreter (i.e. the result of 'which perl'). +# The default file (with absolute path) is: /usr/bin/perl. + +PERL_PATH = /usr/bin/perl + +#--------------------------------------------------------------------------- +# Configuration options related to the dot tool +#--------------------------------------------------------------------------- + +# If the CLASS_DIAGRAMS tag is set to YES, doxygen will generate a class diagram +# (in HTML and LaTeX) for classes with base or super classes. Setting the tag to +# NO turns the diagrams off. Note that this option also works with HAVE_DOT +# disabled, but it is recommended to install and use dot, since it yields more +# powerful graphs. +# The default value is: YES. + +CLASS_DIAGRAMS = YES + +# You can define message sequence charts within doxygen comments using the \msc +# command. Doxygen will then run the mscgen tool (see: +# http://www.mcternan.me.uk/mscgen/)) to produce the chart and insert it in the +# documentation. The MSCGEN_PATH tag allows you to specify the directory where +# the mscgen tool resides. If left empty the tool is assumed to be found in the +# default search path. + +MSCGEN_PATH = + +# You can include diagrams made with dia in doxygen documentation. Doxygen will +# then run dia to produce the diagram and insert it in the documentation. The +# DIA_PATH tag allows you to specify the directory where the dia binary resides. +# If left empty dia is assumed to be found in the default search path. + +DIA_PATH = + +# If set to YES the inheritance and collaboration graphs will hide inheritance +# and usage relations if the target is undocumented or is not a class. +# The default value is: YES. + +HIDE_UNDOC_RELATIONS = YES + +# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is +# available from the path. This tool is part of Graphviz (see: +# http://www.graphviz.org/), a graph visualization toolkit from AT&T and Lucent +# Bell Labs. The other options in this section have no effect if this option is +# set to NO +# The default value is: NO. + +HAVE_DOT = NO + +# The DOT_NUM_THREADS specifies the number of dot invocations doxygen is allowed +# to run in parallel. When set to 0 doxygen will base this on the number of +# processors available in the system. You can set it explicitly to a value +# larger than 0 to get control over the balance between CPU load and processing +# speed. +# Minimum value: 0, maximum value: 32, default value: 0. +# This tag requires that the tag HAVE_DOT is set to YES. + +DOT_NUM_THREADS = 0 + +# When you want a differently looking font in the dot files that doxygen +# generates you can specify the font name using DOT_FONTNAME. You need to make +# sure dot is able to find the font, which can be done by putting it in a +# standard location or by setting the DOTFONTPATH environment variable or by +# setting DOT_FONTPATH to the directory containing the font. +# The default value is: Helvetica. +# This tag requires that the tag HAVE_DOT is set to YES. + +DOT_FONTNAME = Helvetica + +# The DOT_FONTSIZE tag can be used to set the size (in points) of the font of +# dot graphs. +# Minimum value: 4, maximum value: 24, default value: 10. +# This tag requires that the tag HAVE_DOT is set to YES. + +DOT_FONTSIZE = 10 + +# By default doxygen will tell dot to use the default font as specified with +# DOT_FONTNAME. If you specify a different font using DOT_FONTNAME you can set +# the path where dot can find it using this tag. +# This tag requires that the tag HAVE_DOT is set to YES. + +DOT_FONTPATH = + +# If the CLASS_GRAPH tag is set to YES then doxygen will generate a graph for +# each documented class showing the direct and indirect inheritance relations. +# Setting this tag to YES will force the CLASS_DIAGRAMS tag to NO. +# The default value is: YES. +# This tag requires that the tag HAVE_DOT is set to YES. + +CLASS_GRAPH = YES + +# If the COLLABORATION_GRAPH tag is set to YES then doxygen will generate a +# graph for each documented class showing the direct and indirect implementation +# dependencies (inheritance, containment, and class references variables) of the +# class with other documented classes. +# The default value is: YES. +# This tag requires that the tag HAVE_DOT is set to YES. + +COLLABORATION_GRAPH = YES + +# If the GROUP_GRAPHS tag is set to YES then doxygen will generate a graph for +# groups, showing the direct groups dependencies. +# The default value is: YES. +# This tag requires that the tag HAVE_DOT is set to YES. + +GROUP_GRAPHS = YES + +# If the UML_LOOK tag is set to YES, doxygen will generate inheritance and +# collaboration diagrams in a style similar to the OMG's Unified Modeling +# Language. +# The default value is: NO. +# This tag requires that the tag HAVE_DOT is set to YES. + +UML_LOOK = NO + +# If the UML_LOOK tag is enabled, the fields and methods are shown inside the +# class node. If there are many fields or methods and many nodes the graph may +# become too big to be useful. The UML_LIMIT_NUM_FIELDS threshold limits the +# number of items for each type to make the size more manageable. Set this to 0 +# for no limit. Note that the threshold may be exceeded by 50% before the limit +# is enforced. So when you set the threshold to 10, up to 15 fields may appear, +# but if the number exceeds 15, the total amount of fields shown is limited to +# 10. +# Minimum value: 0, maximum value: 100, default value: 10. +# This tag requires that the tag HAVE_DOT is set to YES. + +UML_LIMIT_NUM_FIELDS = 10 + +# If the TEMPLATE_RELATIONS tag is set to YES then the inheritance and +# collaboration graphs will show the relations between templates and their +# instances. +# The default value is: NO. +# This tag requires that the tag HAVE_DOT is set to YES. + +TEMPLATE_RELATIONS = NO + +# If the INCLUDE_GRAPH, ENABLE_PREPROCESSING and SEARCH_INCLUDES tags are set to +# YES then doxygen will generate a graph for each documented file showing the +# direct and indirect include dependencies of the file with other documented +# files. +# The default value is: YES. +# This tag requires that the tag HAVE_DOT is set to YES. + +INCLUDE_GRAPH = YES + +# If the INCLUDED_BY_GRAPH, ENABLE_PREPROCESSING and SEARCH_INCLUDES tags are +# set to YES then doxygen will generate a graph for each documented file showing +# the direct and indirect include dependencies of the file with other documented +# files. +# The default value is: YES. +# This tag requires that the tag HAVE_DOT is set to YES. + +INCLUDED_BY_GRAPH = YES + +# If the CALL_GRAPH tag is set to YES then doxygen will generate a call +# dependency graph for every global function or class method. +# +# Note that enabling this option will significantly increase the time of a run. +# So in most cases it will be better to enable call graphs for selected +# functions only using the \callgraph command. Disabling a call graph can be +# accomplished by means of the command \hidecallgraph. +# The default value is: NO. +# This tag requires that the tag HAVE_DOT is set to YES. + +CALL_GRAPH = NO + +# If the CALLER_GRAPH tag is set to YES then doxygen will generate a caller +# dependency graph for every global function or class method. +# +# Note that enabling this option will significantly increase the time of a run. +# So in most cases it will be better to enable caller graphs for selected +# functions only using the \callergraph command. Disabling a caller graph can be +# accomplished by means of the command \hidecallergraph. +# The default value is: NO. +# This tag requires that the tag HAVE_DOT is set to YES. + +CALLER_GRAPH = NO + +# If the GRAPHICAL_HIERARCHY tag is set to YES then doxygen will graphical +# hierarchy of all classes instead of a textual one. +# The default value is: YES. +# This tag requires that the tag HAVE_DOT is set to YES. + +GRAPHICAL_HIERARCHY = YES + +# If the DIRECTORY_GRAPH tag is set to YES then doxygen will show the +# dependencies a directory has on other directories in a graphical way. The +# dependency relations are determined by the #include relations between the +# files in the directories. +# The default value is: YES. +# This tag requires that the tag HAVE_DOT is set to YES. + +DIRECTORY_GRAPH = YES + +# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images +# generated by dot. For an explanation of the image formats see the section +# output formats in the documentation of the dot tool (Graphviz (see: +# http://www.graphviz.org/)). +# Note: If you choose svg you need to set HTML_FILE_EXTENSION to xhtml in order +# to make the SVG files visible in IE 9+ (other browsers do not have this +# requirement). +# Possible values are: png, jpg, gif, svg, png:gd, png:gd:gd, png:cairo, +# png:cairo:gd, png:cairo:cairo, png:cairo:gdiplus, png:gdiplus and +# png:gdiplus:gdiplus. +# The default value is: png. +# This tag requires that the tag HAVE_DOT is set to YES. + +DOT_IMAGE_FORMAT = png + +# If DOT_IMAGE_FORMAT is set to svg, then this option can be set to YES to +# enable generation of interactive SVG images that allow zooming and panning. +# +# Note that this requires a modern browser other than Internet Explorer. Tested +# and working are Firefox, Chrome, Safari, and Opera. +# Note: For IE 9+ you need to set HTML_FILE_EXTENSION to xhtml in order to make +# the SVG files visible. Older versions of IE do not have SVG support. +# The default value is: NO. +# This tag requires that the tag HAVE_DOT is set to YES. + +INTERACTIVE_SVG = NO + +# The DOT_PATH tag can be used to specify the path where the dot tool can be +# found. If left blank, it is assumed the dot tool can be found in the path. +# This tag requires that the tag HAVE_DOT is set to YES. + +DOT_PATH = + +# The DOTFILE_DIRS tag can be used to specify one or more directories that +# contain dot files that are included in the documentation (see the \dotfile +# command). +# This tag requires that the tag HAVE_DOT is set to YES. + +DOTFILE_DIRS = + +# The MSCFILE_DIRS tag can be used to specify one or more directories that +# contain msc files that are included in the documentation (see the \mscfile +# command). + +MSCFILE_DIRS = + +# The DIAFILE_DIRS tag can be used to specify one or more directories that +# contain dia files that are included in the documentation (see the \diafile +# command). + +DIAFILE_DIRS = + +# When using plantuml, the PLANTUML_JAR_PATH tag should be used to specify the +# path where java can find the plantuml.jar file. If left blank, it is assumed +# PlantUML is not used or called during a preprocessing step. Doxygen will +# generate a warning when it encounters a \startuml command in this case and +# will not generate output for the diagram. + +PLANTUML_JAR_PATH = + +# When using plantuml, the PLANTUML_CFG_FILE tag can be used to specify a +# configuration file for plantuml. + +PLANTUML_CFG_FILE = + +# When using plantuml, the specified paths are searched for files specified by +# the !include statement in a plantuml block. + +PLANTUML_INCLUDE_PATH = + +# The DOT_GRAPH_MAX_NODES tag can be used to set the maximum number of nodes +# that will be shown in the graph. If the number of nodes in a graph becomes +# larger than this value, doxygen will truncate the graph, which is visualized +# by representing a node as a red box. Note that doxygen if the number of direct +# children of the root node in a graph is already larger than +# DOT_GRAPH_MAX_NODES then the graph will not be shown at all. Also note that +# the size of a graph can be further restricted by MAX_DOT_GRAPH_DEPTH. +# Minimum value: 0, maximum value: 10000, default value: 50. +# This tag requires that the tag HAVE_DOT is set to YES. + +DOT_GRAPH_MAX_NODES = 50 + +# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the graphs +# generated by dot. A depth value of 3 means that only nodes reachable from the +# root by following a path via at most 3 edges will be shown. Nodes that lay +# further from the root node will be omitted. Note that setting this option to 1 +# or 2 may greatly reduce the computation time needed for large code bases. Also +# note that the size of a graph can be further restricted by +# DOT_GRAPH_MAX_NODES. Using a depth of 0 means no depth restriction. +# Minimum value: 0, maximum value: 1000, default value: 0. +# This tag requires that the tag HAVE_DOT is set to YES. + +MAX_DOT_GRAPH_DEPTH = 0 + +# Set the DOT_TRANSPARENT tag to YES to generate images with a transparent +# background. This is disabled by default, because dot on Windows does not seem +# to support this out of the box. +# +# Warning: Depending on the platform used, enabling this option may lead to +# badly anti-aliased labels on the edges of a graph (i.e. they become hard to +# read). +# The default value is: NO. +# This tag requires that the tag HAVE_DOT is set to YES. + +DOT_TRANSPARENT = NO + +# Set the DOT_MULTI_TARGETS tag to YES to allow dot to generate multiple output +# files in one run (i.e. multiple -o and -T options on the command line). This +# makes dot run faster, but since only newer versions of dot (>1.8.10) support +# this, this feature is disabled by default. +# The default value is: NO. +# This tag requires that the tag HAVE_DOT is set to YES. + +DOT_MULTI_TARGETS = NO + +# If the GENERATE_LEGEND tag is set to YES doxygen will generate a legend page +# explaining the meaning of the various boxes and arrows in the dot generated +# graphs. +# The default value is: YES. +# This tag requires that the tag HAVE_DOT is set to YES. + +GENERATE_LEGEND = YES + +# If the DOT_CLEANUP tag is set to YES, doxygen will remove the intermediate dot +# files that are used to generate the various graphs. +# The default value is: YES. +# This tag requires that the tag HAVE_DOT is set to YES. + +DOT_CLEANUP = YES diff --git a/packages/CLI11/docs/mainpage.md b/packages/CLI11/docs/mainpage.md new file mode 100644 index 0000000000000000000000000000000000000000..7f97f62ff4402dcfec37b0e5c62ab6b77e67e439 --- /dev/null +++ b/packages/CLI11/docs/mainpage.md @@ -0,0 +1,24 @@ +# Introduction + +This is the Doxygen API documentation for CLI11 parser. There is a friendly introduction to CLI11 on the [Github page](https://github.com/CLIUtils/CLI11). + +The main classes are: + +| Name | Where used | +|---------------|-------------------------------------| +|CLI::Option | Options, stored in the app | +|CLI::App | The main application or subcommands | +|CLI::ExitCode | A scoped enum with exit codes | +|CLI::Timer | A timer class, only in CLI/Timer.hpp (not in `CLI11.hpp`) | +|CLI::AutoTimer | A timer that prints on deletion | + + +Groups of related topics: + +| Name | Description | +|----------------------|------------------------------------------------| +| @ref error_group | Errors that can be thrown | +| @ref validator_group | Common validators used in CLI::Option::check() | + + + diff --git a/packages/CLI11/examples/CMakeLists.txt b/packages/CLI11/examples/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..c2eef50cc20589d0c24004347da72be7fd1d3eea --- /dev/null +++ b/packages/CLI11/examples/CMakeLists.txt @@ -0,0 +1,25 @@ +function(add_cli_exe T) + add_executable(${T} ${ARGN} ${CLI_headers}) + target_link_libraries(${T} PUBLIC CLI11) + set_target_properties( + ${T} PROPERTIES + FOLDER "Examples" + ) + + if(CLANG_TIDY_EXE) + set_target_properties( + ${T} PROPERTIES + CXX_CLANG_TIDY "${DO_CLANG_TIDY}" + ) + endif() +endfunction() + +add_cli_exe(simple simple.cpp) +add_cli_exe(subcommands subcommands.cpp) +add_cli_exe(groups groups.cpp) +add_cli_exe(inter_argument_order inter_argument_order.cpp) +add_cli_exe(prefix_command prefix_command.cpp) +add_cli_exe(enum enum.cpp) +add_cli_exe(modhelp modhelp.cpp) + +add_subdirectory(subcom_in_files) diff --git a/packages/CLI11/examples/enum.cpp b/packages/CLI11/examples/enum.cpp new file mode 100644 index 0000000000000000000000000000000000000000..827bee3925a0f7427d4e9dc4e824b19a6ec7b299 --- /dev/null +++ b/packages/CLI11/examples/enum.cpp @@ -0,0 +1,15 @@ +#include <CLI/CLI.hpp> + +enum Level : std::int32_t { High, Medium, Low }; + +int main(int argc, char **argv) { + CLI::App app; + + Level level; + app.add_set("-l,--level", level, {High, Medium, Low}, "Level settings") + ->set_type_name("enum/Level in {High=0, Medium=1, Low=2}"); + + CLI11_PARSE(app, argc, argv); + + return 0; +} diff --git a/packages/CLI11/examples/groups.cpp b/packages/CLI11/examples/groups.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f8de448fd926f45895af01e19e4d42118c38313f --- /dev/null +++ b/packages/CLI11/examples/groups.cpp @@ -0,0 +1,31 @@ +#include "CLI/CLI.hpp" +#include "CLI/Timer.hpp" + +int main(int argc, char **argv) { + CLI::AutoTimer("This is a timer"); + + CLI::App app("K3Pi goofit fitter"); + + std::string file; + CLI::Option *opt = app.add_option("-f,--file,file", file, "File name")->required()->group("Important"); + + int count; + CLI::Option *copt = app.add_flag("-c,--count", count, "Counter")->required()->group("Important"); + + double value; // = 3.14; + app.add_option("-d,--double", value, "Some Value")->group("Other"); + + try { + app.parse(argc, argv); + } catch(const CLI::ParseError &e) { + return app.exit(e); + } + + std::cout << "Working on file: " << file << ", direct count: " << app.count("--file") + << ", opt count: " << opt->count() << std::endl; + std::cout << "Working on count: " << count << ", direct count: " << app.count("--count") + << ", opt count: " << copt->count() << std::endl; + std::cout << "Some value: " << value << std::endl; + + return 0; +} diff --git a/packages/CLI11/examples/inter_argument_order.cpp b/packages/CLI11/examples/inter_argument_order.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6609fd8be7b59d3f3f89e59ecc8c5c4bbf35b628 --- /dev/null +++ b/packages/CLI11/examples/inter_argument_order.cpp @@ -0,0 +1,45 @@ +#include <CLI/CLI.hpp> +#include <iostream> +#include <vector> +#include <tuple> +#include <algorithm> + +int main(int argc, char **argv) { + CLI::App app; + + std::vector<int> foos; + auto foo = app.add_option("--foo,-f", foos); + + std::vector<int> bars; + auto bar = app.add_option("--bar", bars); + + app.add_flag("--z,--x"); // Random other flags + + // Standard parsing lines (copy and paste in, or use CLI11_PARSE) + try { + app.parse(argc, argv); + } catch(const CLI::ParseError &e) { + return app.exit(e); + } + + // I perfer using the back and popping + std::reverse(std::begin(foos), std::end(foos)); + std::reverse(std::begin(bars), std::end(bars)); + + std::vector<std::pair<std::string, int>> keyval; + for(auto option : app.parse_order()) { + if(option == foo) { + keyval.emplace_back("foo", foos.back()); + foos.pop_back(); + } + if(option == bar) { + keyval.emplace_back("bar", bars.back()); + bars.pop_back(); + } + } + + // Prove the vector is correct + for(auto &pair : keyval) { + std::cout << pair.first << " : " << pair.second << std::endl; + } +} diff --git a/packages/CLI11/examples/modhelp.cpp b/packages/CLI11/examples/modhelp.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7533bf69c0c5b5364908d2e2c997fce4ac0fb37c --- /dev/null +++ b/packages/CLI11/examples/modhelp.cpp @@ -0,0 +1,31 @@ +// Modify the help print so that argument values are accessible +// Note that this will not shortcut `->required` and other similar options + +#include "CLI/CLI.hpp" + +#include <iostream> + +int main(int argc, char **argv) { + CLI::App test; + + // Remove help flag because it shortcuts all processing + test.set_help_flag(); + + // Add custom flag that activates help + auto help = test.add_flag("-h,--help", "Request help"); + + std::string some_option; + test.add_option("-a", some_option, "Some description"); + + try { + test.parse(argc, argv); + if(*help) + throw CLI::CallForHelp(); + } catch(const CLI::Error &e) { + std::cout << "Option string:" << some_option << std::endl; + return test.exit(e); + } + + std::cout << "Option string:" << some_option << std::endl; + return 0; +} diff --git a/packages/CLI11/examples/prefix_command.cpp b/packages/CLI11/examples/prefix_command.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3a3a6f0921908c35c1fb54c29f125f354e47e6d7 --- /dev/null +++ b/packages/CLI11/examples/prefix_command.cpp @@ -0,0 +1,28 @@ +#include "CLI/CLI.hpp" + +int main(int argc, char **argv) { + + CLI::App app("Prefix command app"); + app.prefix_command(); + + std::vector<int> vals; + app.add_option("--vals,-v", vals)->expected(1); + + CLI11_PARSE(app, argc, argv); + + std::vector<std::string> more_comms = app.remaining(); + + std::cout << "Prefix:"; + for(int v : vals) + std::cout << v << ":"; + + std::cout << std::endl << "Remaining commands: "; + + // Perfer to loop over from beginning, not "pop" order + std::reverse(std::begin(more_comms), std::end(more_comms)); + for(auto com : more_comms) + std::cout << com << " "; + std::cout << std::endl; + + return 0; +} diff --git a/packages/CLI11/examples/simple.cpp b/packages/CLI11/examples/simple.cpp new file mode 100644 index 0000000000000000000000000000000000000000..612fd9e027787dc7bd63ac675512db8a8947f0fe --- /dev/null +++ b/packages/CLI11/examples/simple.cpp @@ -0,0 +1,29 @@ +#include "CLI/CLI.hpp" + +int main(int argc, char **argv) { + + CLI::App app("K3Pi goofit fitter"); + + std::string file; + CLI::Option *opt = app.add_option("-f,--file,file", file, "File name"); + + int count; + CLI::Option *copt = app.add_option("-c,--count", count, "Counter"); + + int v; + CLI::Option *flag = app.add_flag("--flag", v, "Some flag that can be passed multiple times"); + + double value; // = 3.14; + app.add_option("-d,--double", value, "Some Value"); + + CLI11_PARSE(app, argc, argv); + + std::cout << "Working on file: " << file << ", direct count: " << app.count("--file") + << ", opt count: " << opt->count() << std::endl; + std::cout << "Working on count: " << count << ", direct count: " << app.count("--count") + << ", opt count: " << copt->count() << std::endl; + std::cout << "Recieved flag: " << v << " (" << flag->count() << ") times\n"; + std::cout << "Some value: " << value << std::endl; + + return 0; +} diff --git a/packages/CLI11/examples/subcom_in_files/CMakeLists.txt b/packages/CLI11/examples/subcom_in_files/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..be283a6bdb0a89c97570cf93b05ec95717564596 --- /dev/null +++ b/packages/CLI11/examples/subcom_in_files/CMakeLists.txt @@ -0,0 +1 @@ +add_cli_exe(main main.cpp subcommand_a.cpp subcommand_a.hpp) diff --git a/packages/CLI11/examples/subcom_in_files/main.cpp b/packages/CLI11/examples/subcom_in_files/main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3befa7a9ad4502f52b38e94837a1d9a5a145f2c7 --- /dev/null +++ b/packages/CLI11/examples/subcom_in_files/main.cpp @@ -0,0 +1,23 @@ +// =================================================================== +// main.cpp +// =================================================================== + +#include "subcommand_a.hpp" + +int main(int argc, char **argv) { + CLI::App app{"..."}; + + // Call the setup functions for the subcommands. + // They are kept alive by a shared pointer in the + // lambda function held by CLI11 + setup_subcommand_a(app); + + // Make sure we get at least one subcommand + app.require_subcommand(); + + // More setup if needed, i.e., other subcommands etc. + + CLI11_PARSE(app, argc, argv); + + return 0; +} diff --git a/packages/CLI11/examples/subcom_in_files/subcommand_a.cpp b/packages/CLI11/examples/subcom_in_files/subcommand_a.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e347148fc82e3081cb308c4c2b375c732fa3e17a --- /dev/null +++ b/packages/CLI11/examples/subcom_in_files/subcommand_a.cpp @@ -0,0 +1,33 @@ +// =================================================================== +// subcommand_a.cpp +// =================================================================== + +#include "subcommand_a.hpp" + +/// Set up a subcommand and capture a shared_ptr to a struct that holds all its options. +/// The variables of the struct are bound to the CLI options. +/// We use a shared ptr so that the addresses of the variables remain for binding, +/// You could return the shared pointer if you wanted to access the values in main. +void setup_subcommand_a(CLI::App &app) { + // Create the option and subcommand objects. + auto opt = std::make_shared<SubcommandAOptions>(); + auto sub = app.add_subcommand("subcommand_a", "performs subcommand a"); + + // Add options to sub, binding them to opt. + sub->add_option("-f,--file", opt->file, "File name")->required(); + sub->add_flag("--with-foo", opt->with_foo, "Counter"); + + // Set the run function as callback to be called when this subcommand is issued. + sub->set_callback([opt]() { run_subcommand_a(*opt); }); +} + +/// The function that runs our code. +/// This could also simply be in the callback lambda itself, +/// but having a separate function is cleaner. +void run_subcommand_a(SubcommandAOptions const &opt) { + // Do stuff... + std::cout << "Working on file: " << opt.file << std::endl; + if(opt.with_foo) { + std::cout << "Using foo!" << std::endl; + } +} diff --git a/packages/CLI11/examples/subcom_in_files/subcommand_a.hpp b/packages/CLI11/examples/subcom_in_files/subcommand_a.hpp new file mode 100644 index 0000000000000000000000000000000000000000..90625650a9c1f48c274f7631b2701dfd64ac16d2 --- /dev/null +++ b/packages/CLI11/examples/subcom_in_files/subcommand_a.hpp @@ -0,0 +1,20 @@ +// =================================================================== +// subcommand_a.hpp +// =================================================================== + +#include "CLI/CLI.hpp" +#include <memory> +#include <string> + +/// Collection of all options of Subcommand A. +struct SubcommandAOptions { + std::string file; + bool with_foo; +}; + +// We could manually make a few variables and use shared pointers for each; this +// is just done this way to be nicely organized + +// Function declarations. +void setup_subcommand_a(CLI::App &app); +void run_subcommand_a(SubcommandAOptions const &opt); diff --git a/packages/CLI11/examples/subcommands.cpp b/packages/CLI11/examples/subcommands.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a28b2aac2ef6fe273caa18d0d51e91eef34939b3 --- /dev/null +++ b/packages/CLI11/examples/subcommands.cpp @@ -0,0 +1,23 @@ +#include "CLI/CLI.hpp" + +int main(int argc, char **argv) { + + CLI::App app("K3Pi goofit fitter"); + app.add_flag("--random", "Some random flag"); + CLI::App *start = app.add_subcommand("start", "A great subcommand"); + CLI::App *stop = app.add_subcommand("stop", "Do you really want to stop?"); + + std::string file; + start->add_option("-f,--file", file, "File name"); + + CLI::Option *s = stop->add_flag("-c,--count", "Counter"); + + CLI11_PARSE(app, argc, argv); + + std::cout << "Working on file: " << file << ", direct count: " << start->count("--file") << std::endl; + std::cout << "Working on count: " << s->count() << ", direct count: " << stop->count("--count") << std::endl; + for(auto subcom : app.get_subcommands()) + std::cout << "Subcommand:" << subcom->get_name() << std::endl; + + return 0; +} diff --git a/packages/CLI11/include/CLI/App.hpp b/packages/CLI11/include/CLI/App.hpp new file mode 100644 index 0000000000000000000000000000000000000000..8fd85e4709e40cf421b7f8a56c3a6c84b4637796 --- /dev/null +++ b/packages/CLI11/include/CLI/App.hpp @@ -0,0 +1,1522 @@ +#pragma once + +// Distributed under the 3-Clause BSD License. See accompanying +// file LICENSE or https://github.com/CLIUtils/CLI11 for details. + +#include <algorithm> +#include <deque> +#include <functional> +#include <iostream> +#include <memory> +#include <numeric> +#include <set> +#include <sstream> +#include <string> +#include <utility> +#include <vector> +#include <iterator> + +// CLI Library includes +#include "CLI/Error.hpp" +#include "CLI/Ini.hpp" +#include "CLI/Option.hpp" +#include "CLI/Split.hpp" +#include "CLI/StringTools.hpp" +#include "CLI/TypeTools.hpp" + +namespace CLI { + +#ifndef CLI11_PARSE +#define CLI11_PARSE(app, argc, argv) \ + try { \ + (app).parse((argc), (argv)); \ + } catch(const CLI::ParseError &e) { \ + return (app).exit(e); \ + } +#endif + +namespace detail { +enum class Classifer { NONE, POSITIONAL_MARK, SHORT, LONG, SUBCOMMAND }; +struct AppFriend; +} // namespace detail + +namespace FailureMessage { +std::string simple(const App *app, const Error &e); +std::string help(const App *app, const Error &e); +} // namespace FailureMessage + +class App; + +using App_p = std::unique_ptr<App>; + +/// Creates a command line program, with very few defaults. +/** To use, create a new `Program()` instance with `argc`, `argv`, and a help description. The templated + * add_option methods make it easy to prepare options. Remember to call `.start` before starting your + * program, so that the options can be evaluated and the help option doesn't accidentally run your program. */ +class App { + friend Option; + friend detail::AppFriend; + + protected: + // This library follows the Google style guide for member names ending in underscores + + /// @name Basics + ///@{ + + /// Subcommand name or program name (from parser) + std::string name_{"program"}; + + /// Description of the current program/subcommand + std::string description_; + + /// If true, allow extra arguments (ie, don't throw an error). INHERITABLE + bool allow_extras_{false}; + + /// If true, allow extra arguments in the ini file (ie, don't throw an error). INHERITABLE + bool allow_ini_extras_{false}; + + /// If true, return immediately on an unrecognised option (implies allow_extras) INHERITABLE + bool prefix_command_{false}; + + /// This is a function that runs when complete. Great for subcommands. Can throw. + std::function<void()> callback_; + + ///@} + /// @name Options + ///@{ + + /// The default values for options, customizable and changeable INHERITABLE + OptionDefaults option_defaults_; + + /// The list of options, stored locally + std::vector<Option_p> options_; + + ///@} + /// @name Help + ///@{ + + /// Footer to put after all options in the help output INHERITABLE + std::string footer_; + + /// A pointer to the help flag if there is one INHERITABLE + Option *help_ptr_{nullptr}; + + /// The error message printing function INHERITABLE + std::function<std::string(const App *, const Error &e)> failure_message_ = FailureMessage::simple; + + ///@} + /// @name Parsing + ///@{ + + using missing_t = std::vector<std::pair<detail::Classifer, std::string>>; + + /// Pair of classifier, string for missing options. (extra detail is removed on returning from parse) + /// + /// This is faster and cleaner than storing just a list of strings and reparsing. This may contain the -- separator. + missing_t missing_; + + /// This is a list of pointers to options with the original parse order + std::vector<Option *> parse_order_; + + /// This is a list of the subcommands collected, in order + std::vector<App *> parsed_subcommands_; + + ///@} + /// @name Subcommands + ///@{ + + /// Storage for subcommand list + std::vector<App_p> subcommands_; + + /// If true, the program name is not case sensitive INHERITABLE + bool ignore_case_{false}; + + /// Allow subcommand fallthrough, so that parent commands can collect commands after subcommand. INHERITABLE + bool fallthrough_{false}; + + /// A pointer to the parent if this is a subcommand + App *parent_{nullptr}; + + /// True if this command/subcommand was parsed + bool parsed_{false}; + + /// Minimum required subcommands + size_t require_subcommand_min_ = 0; + + /// Max number of subcommands allowed (parsing stops after this number). 0 is unlimited INHERITABLE + size_t require_subcommand_max_ = 0; + + /// The group membership INHERITABLE + std::string group_{"Subcommands"}; + + ///@} + /// @name Config + ///@{ + + /// The name of the connected config file + std::string config_name_; + + /// True if ini is required (throws if not present), if false simply keep going. + bool config_required_{false}; + + /// Pointer to the config option + Option *config_ptr_{nullptr}; + + ///@} + + /// Special private constructor for subcommand + App(std::string description_, App *parent) : description_(std::move(description_)), parent_(parent) { + // Inherit if not from a nullptr + if(parent_ != nullptr) { + if(parent_->help_ptr_ != nullptr) + set_help_flag(parent_->help_ptr_->get_name(), parent_->help_ptr_->get_description()); + + /// OptionDefaults + option_defaults_ = parent_->option_defaults_; + + // INHERITABLE + failure_message_ = parent_->failure_message_; + allow_extras_ = parent_->allow_extras_; + allow_ini_extras_ = parent_->allow_ini_extras_; + prefix_command_ = parent_->prefix_command_; + ignore_case_ = parent_->ignore_case_; + fallthrough_ = parent_->fallthrough_; + group_ = parent_->group_; + footer_ = parent_->footer_; + require_subcommand_max_ = parent_->require_subcommand_max_; + } + } + + public: + /// @name Basic + ///@{ + + /// Create a new program. Pass in the same arguments as main(), along with a help string. + App(std::string description_ = "") : App(description_, nullptr) { + set_help_flag("-h,--help", "Print this help message and exit"); + } + + /// Set a callback for the end of parsing. + /// + /// Due to a bug in c++11, + /// it is not possible to overload on std::function (fixed in c++14 + /// and backported to c++11 on newer compilers). Use capture by reference + /// to get a pointer to App if needed. + App *set_callback(std::function<void()> callback) { + callback_ = callback; + return this; + } + + /// Remove the error when extras are left over on the command line. + App *allow_extras(bool allow = true) { + allow_extras_ = allow; + return this; + } + + /// Remove the error when extras are left over on the command line. + /// Will also call App::allow_extras(). + App *allow_ini_extras(bool allow = true) { + allow_extras(allow); + allow_ini_extras_ = allow; + return this; + } + + /// Do not parse anything after the first unrecognised option and return + App *prefix_command(bool allow = true) { + prefix_command_ = allow; + return this; + } + + /// Ignore case. Subcommand inherit value. + App *ignore_case(bool value = true) { + ignore_case_ = value; + if(parent_ != nullptr) { + for(const auto &subc : parent_->subcommands_) { + if(subc.get() != this && (this->check_name(subc->name_) || subc->check_name(this->name_))) + throw OptionAlreadyAdded(subc->name_); + } + } + return this; + } + + /// Check to see if this subcommand was parsed, true only if received on command line. + bool parsed() const { return parsed_; } + + /// Get the OptionDefault object, to set option defaults + OptionDefaults *option_defaults() { return &option_defaults_; } + + ///@} + /// @name Adding options + ///@{ + + /// Add an option, will automatically understand the type for common types. + /// + /// To use, create a variable with the expected type, and pass it in after the name. + /// After start is called, you can use count to see if the value was passed, and + /// the value will be initialized properly. Numbers, vectors, and strings are supported. + /// + /// ->required(), ->default, and the validators are options, + /// The positional options take an optional number of arguments. + /// + /// For example, + /// + /// std::string filename; + /// program.add_option("filename", filename, "description of filename"); + /// + Option *add_option(std::string name, callback_t callback, std::string description = "", bool defaulted = false) { + Option myopt{name, description, callback, defaulted, this}; + + if(std::find_if(std::begin(options_), std::end(options_), [&myopt](const Option_p &v) { + return *v == myopt; + }) == std::end(options_)) { + options_.emplace_back(); + Option_p &option = options_.back(); + option.reset(new Option(name, description, callback, defaulted, this)); + option_defaults_.copy_to(option.get()); + return option.get(); + } else + throw OptionAlreadyAdded(myopt.get_name()); + } + + /// Add option for non-vectors (duplicate copy needed without defaulted to avoid `iostream << value`) + template <typename T, enable_if_t<!is_vector<T>::value, detail::enabler> = detail::dummy> + Option *add_option(std::string name, + T &variable, ///< The variable to set + std::string description = "") { + + std::string simple_name = CLI::detail::split(name, ',').at(0); + CLI::callback_t fun = [&variable, simple_name](CLI::results_t res) { + return detail::lexical_cast(res[0], variable); + }; + + Option *opt = add_option(name, fun, description, false); + opt->set_custom_option(detail::type_name<T>()); + return opt; + } + + /// Add option for non-vectors with a default print + template <typename T, enable_if_t<!is_vector<T>::value, detail::enabler> = detail::dummy> + Option *add_option(std::string name, + T &variable, ///< The variable to set + std::string description, + bool defaulted) { + + std::string simple_name = CLI::detail::split(name, ',').at(0); + CLI::callback_t fun = [&variable, simple_name](CLI::results_t res) { + return detail::lexical_cast(res[0], variable); + }; + + Option *opt = add_option(name, fun, description, defaulted); + opt->set_custom_option(detail::type_name<T>()); + if(defaulted) { + std::stringstream out; + out << variable; + opt->set_default_str(out.str()); + } + return opt; + } + + /// Add option for vectors (no default) + template <typename T> + Option *add_option(std::string name, + std::vector<T> &variable, ///< The variable vector to set + std::string description = "") { + + CLI::callback_t fun = [&variable](CLI::results_t res) { + bool retval = true; + variable.clear(); + for(const auto &a : res) { + variable.emplace_back(); + retval &= detail::lexical_cast(a, variable.back()); + } + return (!variable.empty()) && retval; + }; + + Option *opt = add_option(name, fun, description, false); + opt->set_custom_option(detail::type_name<T>(), -1); + return opt; + } + + /// Add option for vectors + template <typename T> + Option *add_option(std::string name, + std::vector<T> &variable, ///< The variable vector to set + std::string description, + bool defaulted) { + + CLI::callback_t fun = [&variable](CLI::results_t res) { + bool retval = true; + variable.clear(); + for(const auto &a : res) { + variable.emplace_back(); + retval &= detail::lexical_cast(a, variable.back()); + } + return (!variable.empty()) && retval; + }; + + Option *opt = add_option(name, fun, description, defaulted); + opt->set_custom_option(detail::type_name<T>(), -1); + if(defaulted) + opt->set_default_str("[" + detail::join(variable) + "]"); + return opt; + } + + /// Set a help flag, replaced the existing one if present + Option *set_help_flag(std::string name = "", std::string description = "") { + if(help_ptr_ != nullptr) { + remove_option(help_ptr_); + help_ptr_ = nullptr; + } + + // Empty name will simply remove the help flag + if(!name.empty()) { + help_ptr_ = add_flag(name, description); + help_ptr_->configurable(false); + } + + return help_ptr_; + } + + /// Add option for flag + Option *add_flag(std::string name, std::string description = "") { + CLI::callback_t fun = [](CLI::results_t) { return true; }; + + Option *opt = add_option(name, fun, description, false); + if(opt->get_positional()) + throw IncorrectConstruction::PositionalFlag(name); + opt->set_custom_option("", 0); + return opt; + } + + /// Add option for flag integer + template <typename T, + enable_if_t<std::is_integral<T>::value && !is_bool<T>::value, detail::enabler> = detail::dummy> + Option *add_flag(std::string name, + T &count, ///< A variable holding the count + std::string description = "") { + + count = 0; + CLI::callback_t fun = [&count](CLI::results_t res) { + count = static_cast<T>(res.size()); + return true; + }; + + Option *opt = add_option(name, fun, description, false); + if(opt->get_positional()) + throw IncorrectConstruction::PositionalFlag(name); + opt->set_custom_option("", 0); + return opt; + } + + /// Bool version - defaults to allowing multiple passings, but can be forced to one if + /// `multi_option_policy(CLI::MultiOptionPolicy::Throw)` is used. + template <typename T, enable_if_t<is_bool<T>::value, detail::enabler> = detail::dummy> + Option *add_flag(std::string name, + T &count, ///< A variable holding true if passed + std::string description = "") { + + count = false; + CLI::callback_t fun = [&count](CLI::results_t res) { + count = true; + return res.size() == 1; + }; + + Option *opt = add_option(name, fun, description, false); + if(opt->get_positional()) + throw IncorrectConstruction::PositionalFlag(name); + opt->set_custom_option("", 0); + opt->multi_option_policy(CLI::MultiOptionPolicy::TakeLast); + return opt; + } + + /// Add option for callback + Option *add_flag_function(std::string name, + std::function<void(size_t)> function, ///< A function to call, void(size_t) + std::string description = "") { + + CLI::callback_t fun = [function](CLI::results_t res) { + auto count = static_cast<size_t>(res.size()); + function(count); + return true; + }; + + Option *opt = add_option(name, fun, description, false); + if(opt->get_positional()) + throw IncorrectConstruction::PositionalFlag(name); + opt->set_custom_option("", 0); + return opt; + } + +#if __cplusplus >= 201402L + /// Add option for callback (C++14 or better only) + Option *add_flag(std::string name, + std::function<void(size_t)> function, ///< A function to call, void(size_t) + std::string description = "") { + return add_flag_function(name, function, description); + } +#endif + + /// Add set of options (No default) + template <typename T> + Option *add_set(std::string name, + T &member, ///< The selected member of the set + std::set<T> options, ///< The set of possibilities + std::string description = "") { + + std::string simple_name = CLI::detail::split(name, ',').at(0); + CLI::callback_t fun = [&member, options, simple_name](CLI::results_t res) { + bool retval = detail::lexical_cast(res[0], member); + if(!retval) + throw ConversionError(res[0], simple_name); + return std::find(std::begin(options), std::end(options), member) != std::end(options); + }; + + Option *opt = add_option(name, fun, description, false); + std::string typeval = detail::type_name<T>(); + typeval += " in {" + detail::join(options) + "}"; + opt->set_custom_option(typeval); + return opt; + } + + /// Add set of options + template <typename T> + Option *add_set(std::string name, + T &member, ///< The selected member of the set + std::set<T> options, ///< The set of posibilities + std::string description, + bool defaulted) { + + std::string simple_name = CLI::detail::split(name, ',').at(0); + CLI::callback_t fun = [&member, options, simple_name](CLI::results_t res) { + bool retval = detail::lexical_cast(res[0], member); + if(!retval) + throw ConversionError(res[0], simple_name); + return std::find(std::begin(options), std::end(options), member) != std::end(options); + }; + + Option *opt = add_option(name, fun, description, defaulted); + std::string typeval = detail::type_name<T>(); + typeval += " in {" + detail::join(options) + "}"; + opt->set_custom_option(typeval); + if(defaulted) { + std::stringstream out; + out << member; + opt->set_default_str(out.str()); + } + return opt; + } + + /// Add set of options, string only, ignore case (no default) + Option *add_set_ignore_case(std::string name, + std::string &member, ///< The selected member of the set + std::set<std::string> options, ///< The set of possibilities + std::string description = "") { + + std::string simple_name = CLI::detail::split(name, ',').at(0); + CLI::callback_t fun = [&member, options, simple_name](CLI::results_t res) { + member = detail::to_lower(res[0]); + auto iter = std::find_if(std::begin(options), std::end(options), [&member](std::string val) { + return detail::to_lower(val) == member; + }); + if(iter == std::end(options)) + throw ConversionError(member, simple_name); + else { + member = *iter; + return true; + } + }; + + Option *opt = add_option(name, fun, description, false); + std::string typeval = detail::type_name<std::string>(); + typeval += " in {" + detail::join(options) + "}"; + opt->set_custom_option(typeval); + + return opt; + } + + /// Add set of options, string only, ignore case + Option *add_set_ignore_case(std::string name, + std::string &member, ///< The selected member of the set + std::set<std::string> options, ///< The set of posibilities + std::string description, + bool defaulted) { + + std::string simple_name = CLI::detail::split(name, ',').at(0); + CLI::callback_t fun = [&member, options, simple_name](CLI::results_t res) { + member = detail::to_lower(res[0]); + auto iter = std::find_if(std::begin(options), std::end(options), [&member](std::string val) { + return detail::to_lower(val) == member; + }); + if(iter == std::end(options)) + throw ConversionError(member, simple_name); + else { + member = *iter; + return true; + } + }; + + Option *opt = add_option(name, fun, description, defaulted); + std::string typeval = detail::type_name<std::string>(); + typeval += " in {" + detail::join(options) + "}"; + opt->set_custom_option(typeval); + if(defaulted) { + opt->set_default_str(member); + } + return opt; + } + + /// Add a complex number + template <typename T> + Option *add_complex(std::string name, + T &variable, + std::string description = "", + bool defaulted = false, + std::string label = "COMPLEX") { + + std::string simple_name = CLI::detail::split(name, ',').at(0); + CLI::callback_t fun = [&variable, simple_name, label](results_t res) { + if(res[1].back() == 'i') + res[1].pop_back(); + double x, y; + bool worked = detail::lexical_cast(res[0], x) && detail::lexical_cast(res[1], y); + if(worked) + variable = T(x, y); + return worked; + }; + + CLI::Option *opt = add_option(name, fun, description, defaulted); + opt->set_custom_option(label, 2); + if(defaulted) { + std::stringstream out; + out << variable; + opt->set_default_str(out.str()); + } + return opt; + } + + /// Set a configuration ini file option, or clear it if no name passed + Option *set_config(std::string name = "", + std::string default_filename = "", + std::string help = "Read an ini file", + bool required = false) { + + // Remove existing config if present + if(config_ptr_ != nullptr) + remove_option(config_ptr_); + + // Only add config if option passed + if(!name.empty()) { + config_name_ = default_filename; + config_required_ = required; + config_ptr_ = add_option(name, config_name_, help, !default_filename.empty()); + config_ptr_->configurable(false); + } + + return config_ptr_; + } + + /// Removes an option from the App. Takes an option pointer. Returns true if found and removed. + bool remove_option(Option *opt) { + auto iterator = + std::find_if(std::begin(options_), std::end(options_), [opt](const Option_p &v) { return v.get() == opt; }); + if(iterator != std::end(options_)) { + options_.erase(iterator); + return true; + } + return false; + } + + ///@} + /// @name Subcommmands + ///@{ + + /// Add a subcommand. Inherits INHERITABLE and OptionDefaults, and help flag + App *add_subcommand(std::string name, std::string description = "") { + subcommands_.emplace_back(new App(description, this)); + subcommands_.back()->name_ = name; + for(const auto &subc : subcommands_) + if(subc.get() != subcommands_.back().get()) + if(subc->check_name(subcommands_.back()->name_) || subcommands_.back()->check_name(subc->name_)) + throw OptionAlreadyAdded(subc->name_); + return subcommands_.back().get(); + } + + /// Check to see if a subcommand is part of this command (doesn't have to be in command line) + App *get_subcommand(App *subcom) const { + for(const App_p &subcomptr : subcommands_) + if(subcomptr.get() == subcom) + return subcom; + throw OptionNotFound(subcom->get_name()); + } + + /// Check to see if a subcommand is part of this command (text version) + App *get_subcommand(std::string subcom) const { + for(const App_p &subcomptr : subcommands_) + if(subcomptr->check_name(subcom)) + return subcomptr.get(); + throw OptionNotFound(subcom); + } + + /// Changes the group membership + App *group(std::string name) { + group_ = name; + return this; + } + + /// The argumentless form of require subcommand requires 1 or more subcommands + App *require_subcommand() { + require_subcommand_min_ = 1; + require_subcommand_max_ = 0; + return this; + } + + /// Require a subcommand to be given (does not affect help call) + /// The number required can be given. Negative values indicate maximum + /// number allowed (0 for any number). Max number inheritable. + App *require_subcommand(int value) { + if(value < 0) { + require_subcommand_min_ = 0; + require_subcommand_max_ = static_cast<size_t>(-value); + } else { + require_subcommand_min_ = static_cast<size_t>(value); + require_subcommand_max_ = static_cast<size_t>(value); + } + return this; + } + + /// Explicitly control the number of subcommands required. Setting 0 + /// for the max means unlimited number allowed. Max number inheritable. + App *require_subcommand(size_t min, size_t max) { + require_subcommand_min_ = min; + require_subcommand_max_ = max; + return this; + } + + /// Stop subcommand fallthrough, so that parent commands cannot collect commands after subcommand. + /// Default from parent, usually set on parent. + App *fallthrough(bool value = true) { + fallthrough_ = value; + return this; + } + + /// Check to see if this subcommand was parsed, true only if received on command line. + /// This allows the subcommand to be directly checked. + operator bool() const { return parsed_; } + + ///@} + /// @name Extras for subclassing + ///@{ + + /// This allows subclasses to inject code before callbacks but after parse. + /// + /// This does not run if any errors or help is thrown. + virtual void pre_callback() {} + + ///@} + /// @name Parsing + ///@{ + + /// Parses the command line - throws errors + /// This must be called after the options are in but before the rest of the program. + void parse(int argc, char **argv) { + name_ = argv[0]; + std::vector<std::string> args; + for(int i = argc - 1; i > 0; i--) + args.emplace_back(argv[i]); + parse(args); + } + + /// The real work is done here. Expects a reversed vector. + /// Changes the vector to the remaining options. + void parse(std::vector<std::string> &args) { + _validate(); + _parse(args); + run_callback(); + } + + /// Provide a function to print a help message. The function gets access to the App pointer and error. + void set_failure_message(std::function<std::string(const App *, const Error &e)> function) { + failure_message_ = function; + } + + /// Print a nice error message and return the exit code + int exit(const Error &e, std::ostream &out = std::cout, std::ostream &err = std::cerr) const { + + /// Avoid printing anything if this is a CLI::RuntimeError + if(dynamic_cast<const CLI::RuntimeError *>(&e) != nullptr) + return e.get_exit_code(); + + if(dynamic_cast<const CLI::CallForHelp *>(&e) != nullptr) { + out << help(); + return e.get_exit_code(); + } + + if(e.get_exit_code() != static_cast<int>(ExitCodes::Success)) { + if(failure_message_) + err << failure_message_(this, e) << std::flush; + } + + return e.get_exit_code(); + } + + /// Reset the parsed data + void reset() { + + parsed_ = false; + missing_.clear(); + parsed_subcommands_.clear(); + + for(const Option_p &opt : options_) { + opt->clear(); + } + for(const App_p &app : subcommands_) { + app->reset(); + } + } + + ///@} + /// @name Post parsing + ///@{ + + /// Counts the number of times the given option was passed. + size_t count(std::string name) const { + for(const Option_p &opt : options_) { + if(opt->check_name(name)) { + return opt->count(); + } + } + throw OptionNotFound(name); + } + + /// Get a subcommand pointer list to the currently selected subcommands (after parsing by default, in command line + /// order) + std::vector<App *> get_subcommands(bool parsed = true) const { + if(parsed) { + return parsed_subcommands_; + } else { + std::vector<App *> subcomms(subcommands_.size()); + std::transform(std::begin(subcommands_), std::end(subcommands_), std::begin(subcomms), [](const App_p &v) { + return v.get(); + }); + return subcomms; + } + } + + /// Check to see if given subcommand was selected + bool got_subcommand(App *subcom) const { + // get subcom needed to verify that this was a real subcommand + return get_subcommand(subcom)->parsed_; + } + + /// Check with name instead of pointer to see if subcommand was selected + bool got_subcommand(std::string name) const { return get_subcommand(name)->parsed_; } + + ///@} + /// @name Help + ///@{ + + /// Set footer. + App *set_footer(std::string footer) { + footer_ = footer; + return this; + } + + /// Produce a string that could be read in as a config of the current values of the App. Set default_also to include + /// default arguments. Prefix will add a string to the beginning of each option. + std::string + config_to_str(bool default_also = false, std::string prefix = "", bool write_description = false) const { + std::stringstream out; + for(const Option_p &opt : options_) { + + // Only process option with a long-name and configurable + if(!opt->lnames_.empty() && opt->get_configurable()) { + std::string name = prefix + opt->lnames_[0]; + std::string value; + + // Non-flags + if(opt->get_expected() != 0) { + + // If the option was found on command line + if(opt->count() > 0) + value = detail::inijoin(opt->results()); + + // If the option has a default and is requested by optional argument + else if(default_also && !opt->defaultval_.empty()) + value = opt->defaultval_; + // Flag, one passed + } else if(opt->count() == 1) { + value = "true"; + + // Flag, multiple passed + } else if(opt->count() > 1) { + value = std::to_string(opt->count()); + + // Flag, not present + } else if(opt->count() == 0 && default_also) { + value = "false"; + } + + if(!value.empty()) { + if(write_description && opt->has_description()) { + if(static_cast<int>(out.tellp()) != 0) { + out << std::endl; + } + out << "; " << detail::fix_newlines("; ", opt->get_description()) << std::endl; + } + out << name << "=" << value << std::endl; + } + } + } + for(const App_p &subcom : subcommands_) + out << subcom->config_to_str(default_also, prefix + subcom->name_ + "."); + return out.str(); + } + + /// Makes a help message, with a column wid for column 1 + std::string help(size_t wid = 30, std::string prev = "") const { + // Delegate to subcommand if needed + if(prev.empty()) + prev = name_; + else + prev += " " + name_; + + auto selected_subcommands = get_subcommands(); + if(!selected_subcommands.empty()) + return selected_subcommands.at(0)->help(wid, prev); + + std::stringstream out; + out << description_ << std::endl; + out << "Usage: " << prev; + + // Check for options_ + bool npos = false; + std::set<std::string> groups; + for(const Option_p &opt : options_) { + if(opt->nonpositional()) { + npos = true; + groups.insert(opt->get_group()); + } + } + + if(npos) + out << " [OPTIONS]"; + + // Positionals + bool pos = false; + for(const Option_p &opt : options_) + if(opt->get_positional()) { + // A hidden positional should still show up in the usage statement + // if(detail::to_lower(opt->get_group()).empty()) + // continue; + out << " " << opt->help_positional(); + if(opt->_has_help_positional()) + pos = true; + } + + if(!subcommands_.empty()) { + if(require_subcommand_min_ > 0) + out << " SUBCOMMAND"; + else + out << " [SUBCOMMAND]"; + } + + out << std::endl; + + // Positional descriptions + if(pos) { + out << std::endl << "Positionals:" << std::endl; + for(const Option_p &opt : options_) { + if(detail::to_lower(opt->get_group()).empty()) + continue; // Hidden + if(opt->_has_help_positional()) + detail::format_help(out, opt->help_pname(), opt->get_description(), wid); + } + } + + // Options + if(npos) { + for(const std::string &group : groups) { + if(detail::to_lower(group).empty()) + continue; // Hidden + out << std::endl << group << ":" << std::endl; + for(const Option_p &opt : options_) { + if(opt->nonpositional() && opt->get_group() == group) + detail::format_help(out, opt->help_name(true), opt->get_description(), wid); + } + } + } + + // Subcommands + if(!subcommands_.empty()) { + std::set<std::string> subcmd_groups_seen; + for(const App_p &com : subcommands_) { + const std::string &group_key = detail::to_lower(com->get_group()); + if(group_key.empty() || subcmd_groups_seen.count(group_key) != 0) + continue; // Hidden or not in a group + + subcmd_groups_seen.insert(group_key); + out << std::endl << com->get_group() << ":" << std::endl; + for(const App_p &new_com : subcommands_) + if(detail::to_lower(new_com->get_group()) == group_key) + detail::format_help(out, new_com->get_name(), new_com->description_, wid); + } + } + + if(!footer_.empty()) { + out << std::endl << footer_ << std::endl; + } + + return out.str(); + } + + ///@} + /// @name Getters + ///@{ + + /// Check the status of ignore_case + bool get_ignore_case() const { return ignore_case_; } + + /// Check the status of fallthrough + bool get_fallthrough() const { return fallthrough_; } + + /// Get the group of this subcommand + const std::string &get_group() const { return group_; } + + /// Get footer. + std::string get_footer() const { return footer_; } + + /// Get the required min subcommand value + size_t get_require_subcommand_min() const { return require_subcommand_min_; } + + /// Get the required max subcommand value + size_t get_require_subcommand_max() const { return require_subcommand_max_; } + + /// Get the prefix command status + bool get_prefix_command() const { return prefix_command_; } + + /// Get the status of allow extras + bool get_allow_extras() const { return allow_extras_; } + + /// Get the status of allow extras + bool get_allow_ini_extras() const { return allow_ini_extras_; } + + /// Get a pointer to the help flag. + Option *get_help_ptr() { return help_ptr_; } + + /// Get a pointer to the help flag. (const) + const Option *get_help_ptr() const { return help_ptr_; } + + /// Get a pointer to the config option. + Option *get_config_ptr() { return config_ptr_; } + + /// Get the parent of this subcommand (or nullptr if master app) + App *get_parent() { return parent_; } + + /// Get a pointer to the config option. (const) + const Option *get_config_ptr() const { return config_ptr_; } + /// Get the name of the current app + std::string get_name() const { return name_; } + + /// Check the name, case insensitive if set + bool check_name(std::string name_to_check) const { + std::string local_name = name_; + if(ignore_case_) { + local_name = detail::to_lower(name_); + name_to_check = detail::to_lower(name_to_check); + } + + return local_name == name_to_check; + } + + /// This gets a vector of pointers with the original parse order + const std::vector<Option *> &parse_order() const { return parse_order_; } + + /// This retuns the missing options from the current subcommand + std::vector<std::string> remaining(bool recurse = false) const { + std::vector<std::string> miss_list; + for(const std::pair<detail::Classifer, std::string> &miss : missing_) { + miss_list.push_back(std::get<1>(miss)); + } + if(recurse) { + for(const App *sub : parsed_subcommands_) { + std::vector<std::string> output = sub->remaining(recurse); + std::copy(std::begin(output), std::end(output), std::back_inserter(miss_list)); + } + } + return miss_list; + } + + /// This returns the number of remaining options, minus the -- seperator + size_t remaining_size(bool recurse = false) const { + size_t count = std::count_if( + std::begin(missing_), std::end(missing_), [](const std::pair<detail::Classifer, std::string> &val) { + return val.first != detail::Classifer::POSITIONAL_MARK; + }); + if(recurse) { + for(const App_p &sub : subcommands_) { + count += sub->remaining_size(recurse); + } + } + return count; + } + + ///@} + + protected: + /// Check the options to make sure there are no conflicts. + /// + /// Currently checks to see if multiple positionals exist with -1 args + void _validate() const { + auto count = std::count_if(std::begin(options_), std::end(options_), [](const Option_p &opt) { + return opt->get_expected() == -1 && opt->get_positional(); + }); + if(count > 1) + throw InvalidError(name_); + for(const App_p &app : subcommands_) + app->_validate(); + } + + /// Internal function to run (App) callback, top down + void run_callback() { + pre_callback(); + if(callback_) + callback_(); + for(App *subc : get_subcommands()) { + subc->run_callback(); + } + } + + /// Check to see if a subcommand is valid. Give up immediately if subcommand max has been reached. + bool _valid_subcommand(const std::string ¤t) const { + // Don't match if max has been reached - but still check parents + if(require_subcommand_max_ != 0 && parsed_subcommands_.size() >= require_subcommand_max_) { + return parent_ != nullptr && parent_->_valid_subcommand(current); + } + + for(const App_p &com : subcommands_) + if(com->check_name(current) && !*com) + return true; + + // Check parent if exists, else return false + return parent_ != nullptr && parent_->_valid_subcommand(current); + } + + /// Selects a Classifier enum based on the type of the current argument + detail::Classifer _recognize(const std::string ¤t) const { + std::string dummy1, dummy2; + + if(current == "--") + return detail::Classifer::POSITIONAL_MARK; + if(_valid_subcommand(current)) + return detail::Classifer::SUBCOMMAND; + if(detail::split_long(current, dummy1, dummy2)) + return detail::Classifer::LONG; + if(detail::split_short(current, dummy1, dummy2)) + return detail::Classifer::SHORT; + return detail::Classifer::NONE; + } + + /// Internal parse function + void _parse(std::vector<std::string> &args) { + parsed_ = true; + bool positional_only = false; + + while(!args.empty()) { + _parse_single(args, positional_only); + } + + if(help_ptr_ != nullptr && help_ptr_->count() > 0) { + throw CallForHelp(); + } + + // Process an INI file + if(config_ptr_ != nullptr) { + if(*config_ptr_) { + config_ptr_->run_callback(); + config_required_ = true; + } + if(!config_name_.empty()) { + try { + std::vector<detail::ini_ret_t> values = detail::parse_ini(config_name_); + while(!values.empty()) { + if(!_parse_ini(values)) { + throw INIError::Extras(values.back().fullname); + } + } + } catch(const FileError &) { + if(config_required_) + throw; + } + } + } + + // Get envname options if not yet passed + for(const Option_p &opt : options_) { + if(opt->count() == 0 && !opt->envname_.empty()) { + char *buffer = nullptr; + std::string ename_string; + +#ifdef _MSC_VER + // Windows version + size_t sz = 0; + if(_dupenv_s(&buffer, &sz, opt->envname_.c_str()) == 0 && buffer != nullptr) { + ename_string = std::string(buffer); + free(buffer); + } +#else + // This also works on Windows, but gives a warning + buffer = std::getenv(opt->envname_.c_str()); + if(buffer != nullptr) + ename_string = std::string(buffer); +#endif + + if(!ename_string.empty()) { + opt->add_result(ename_string); + } + } + } + + // Process callbacks + for(const Option_p &opt : options_) { + if(opt->count() > 0 && !opt->get_callback_run()) { + opt->run_callback(); + } + } + + // Verify required options + for(const Option_p &opt : options_) { + // Required or partially filled + if(opt->get_required() || opt->count() != 0) { + // Make sure enough -N arguments parsed (+N is already handled in parsing function) + if(opt->get_expected() < 0 && opt->count() < static_cast<size_t>(-opt->get_expected())) + throw ArgumentMismatch::AtLeast(opt->single_name(), -opt->get_expected()); + + // Required but empty + if(opt->get_required() && opt->count() == 0) + throw RequiredError(opt->single_name()); + } + // Requires + for(const Option *opt_req : opt->requires_) + if(opt->count() > 0 && opt_req->count() == 0) + throw RequiresError(opt->single_name(), opt_req->single_name()); + // Excludes + for(const Option *opt_ex : opt->excludes_) + if(opt->count() > 0 && opt_ex->count() != 0) + throw ExcludesError(opt->single_name(), opt_ex->single_name()); + } + + auto selected_subcommands = get_subcommands(); + if(require_subcommand_min_ > selected_subcommands.size()) + throw RequiredError::Subcommand(require_subcommand_min_); + + // Convert missing (pairs) to extras (string only) + if(!(allow_extras_ || prefix_command_)) { + size_t num_left_over = remaining_size(); + if(num_left_over > 0) { + args = remaining(false); + std::reverse(std::begin(args), std::end(args)); + throw ExtrasError(args); + } + } + } + + /// Parse one ini param, return false if not found in any subcommand, remove if it is + /// + /// If this has more than one dot.separated.name, go into the subcommand matching it + /// Returns true if it managed to find the option, if false you'll need to remove the arg manually. + bool _parse_ini(std::vector<detail::ini_ret_t> &args) { + detail::ini_ret_t ¤t = args.back(); + std::string parent = current.parent(); // respects current.level + std::string name = current.name(); + + // If a parent is listed, go to a subcommand + if(!parent.empty()) { + current.level++; + for(const App_p &com : subcommands_) + if(com->check_name(parent)) + return com->_parse_ini(args); + return false; + } + + auto op_ptr = std::find_if( + std::begin(options_), std::end(options_), [name](const Option_p &v) { return v->check_lname(name); }); + + if(op_ptr == std::end(options_)) { + if(allow_ini_extras_) { + // Should we worry about classifying the extras properly? + missing_.emplace_back(detail::Classifer::NONE, current.fullname); + args.pop_back(); + return true; + } + return false; + } + + // Let's not go crazy with pointer syntax + Option_p &op = *op_ptr; + + if(!op->get_configurable()) + throw INIError::NotConfigurable(current.fullname); + + if(op->results_.empty()) { + // Flag parsing + if(op->get_expected() == 0) { + if(current.inputs.size() == 1) { + std::string val = current.inputs.at(0); + val = detail::to_lower(val); + if(val == "true" || val == "on" || val == "yes") + op->results_ = {""}; + else if(val == "false" || val == "off" || val == "no") + ; + else + try { + size_t ui = std::stoul(val); + for(size_t i = 0; i < ui; i++) + op->results_.emplace_back(""); + } catch(const std::invalid_argument &) { + throw ConversionError::TrueFalse(current.fullname); + } + } else + throw ConversionError::TooManyInputsFlag(current.fullname); + } else { + op->results_ = current.inputs; + op->run_callback(); + } + } + + args.pop_back(); + return true; + } + + /// Parse "one" argument (some may eat more than one), delegate to parent if fails, add to missing if missing from + /// master + void _parse_single(std::vector<std::string> &args, bool &positional_only) { + + detail::Classifer classifer = positional_only ? detail::Classifer::NONE : _recognize(args.back()); + switch(classifer) { + case detail::Classifer::POSITIONAL_MARK: + missing_.emplace_back(classifer, args.back()); + args.pop_back(); + positional_only = true; + break; + case detail::Classifer::SUBCOMMAND: + _parse_subcommand(args); + break; + case detail::Classifer::LONG: + // If already parsed a subcommand, don't accept options_ + _parse_arg(args, true); + break; + case detail::Classifer::SHORT: + // If already parsed a subcommand, don't accept options_ + _parse_arg(args, false); + break; + case detail::Classifer::NONE: + // Probably a positional or something for a parent (sub)command + _parse_positional(args); + } + } + + /// Count the required remaining positional arguments + size_t _count_remaining_positionals(bool required = false) const { + size_t retval = 0; + for(const Option_p &opt : options_) + if(opt->get_positional() && (!required || opt->get_required()) && opt->get_expected() > 0 && + static_cast<int>(opt->count()) < opt->get_expected()) + retval = static_cast<size_t>(opt->get_expected()) - opt->count(); + + return retval; + } + + /// Parse a positional, go up the tree to check + void _parse_positional(std::vector<std::string> &args) { + + std::string positional = args.back(); + for(const Option_p &opt : options_) { + // Eat options, one by one, until done + if(opt->get_positional() && + (static_cast<int>(opt->count()) < opt->get_expected() || opt->get_expected() < 0)) { + + opt->add_result(positional); + parse_order_.push_back(opt.get()); + args.pop_back(); + return; + } + } + + if(parent_ != nullptr && fallthrough_) + return parent_->_parse_positional(args); + else { + args.pop_back(); + missing_.emplace_back(detail::Classifer::NONE, positional); + + if(prefix_command_) { + while(!args.empty()) { + missing_.emplace_back(detail::Classifer::NONE, args.back()); + args.pop_back(); + } + } + } + } + + /// Parse a subcommand, modify args and continue + /// + /// Unlike the others, this one will always allow fallthrough + void _parse_subcommand(std::vector<std::string> &args) { + if(_count_remaining_positionals(/* required */ true) > 0) + return _parse_positional(args); + for(const App_p &com : subcommands_) { + if(com->check_name(args.back())) { + args.pop_back(); + if(std::find(std::begin(parsed_subcommands_), std::end(parsed_subcommands_), com.get()) == + std::end(parsed_subcommands_)) + parsed_subcommands_.push_back(com.get()); + com->_parse(args); + return; + } + } + if(parent_ != nullptr) + return parent_->_parse_subcommand(args); + else + throw HorribleError("Subcommand " + args.back() + " missing"); + } + + /// Parse a short (false) or long (true) argument, must be at the top of the list + void _parse_arg(std::vector<std::string> &args, bool second_dash) { + + detail::Classifer current_type = second_dash ? detail::Classifer::LONG : detail::Classifer::SHORT; + + std::string current = args.back(); + + std::string name; + std::string value; + std::string rest; + + if(second_dash) { + if(!detail::split_long(current, name, value)) + throw HorribleError("Long parsed but missing (you should not see this):" + args.back()); + } else { + if(!detail::split_short(current, name, rest)) + throw HorribleError("Short parsed but missing! You should not see this"); + } + + auto op_ptr = std::find_if(std::begin(options_), std::end(options_), [name, second_dash](const Option_p &opt) { + return second_dash ? opt->check_lname(name) : opt->check_sname(name); + }); + + // Option not found + if(op_ptr == std::end(options_)) { + // If a subcommand, try the master command + if(parent_ != nullptr && fallthrough_) + return parent_->_parse_arg(args, second_dash); + // Otherwise, add to missing + else { + args.pop_back(); + missing_.emplace_back(current_type, current); + return; + } + } + + args.pop_back(); + + // Get a reference to the pointer to make syntax bearable + Option_p &op = *op_ptr; + + int num = op->get_expected(); + + if(!value.empty()) { + if(num != -1) + num--; + op->add_result(value); + parse_order_.push_back(op.get()); + } else if(num == 0) { + op->add_result(""); + parse_order_.push_back(op.get()); + } else if(!rest.empty()) { + if(num > 0) + num--; + op->add_result(rest); + parse_order_.push_back(op.get()); + rest = ""; + } + + // Unlimited vector parser + if(num < 0) { + int collected = 0; // Make sure we always eat the minimum + while(!args.empty() && _recognize(args.back()) == detail::Classifer::NONE) { + if(collected >= -num) { + // We could break here for allow extras, but we don't + + // If any positionals remain, don't keep eating + if(_count_remaining_positionals() > 0) + break; + + // If there are any unlimited positionals, those also take priority + if(std::any_of(std::begin(options_), std::end(options_), [](const Option_p &opt) { + return opt->get_positional() && opt->get_expected() < 0; + })) + break; + } + op->add_result(args.back()); + parse_order_.push_back(op.get()); + args.pop_back(); + collected++; + } + + } else { + while(num > 0 && !args.empty()) { + num--; + std::string current_ = args.back(); + args.pop_back(); + op->add_result(current_); + parse_order_.push_back(op.get()); + } + + if(num > 0) { + throw ArgumentMismatch::TypedAtLeast(op->single_name(), num, op->get_type_name()); + } + } + + if(!rest.empty()) { + rest = "-" + rest; + args.push_back(rest); + } + } +}; + +namespace FailureMessage { + +inline std::string simple(const App *app, const Error &e) { + std::string header = std::string(e.what()) + "\n"; + if(app->get_help_ptr() != nullptr) + header += "Run with " + app->get_help_ptr()->single_name() + " for more information.\n"; + return header; +} + +inline std::string help(const App *app, const Error &e) { + std::string header = std::string("ERROR: ") + e.get_name() + ": " + e.what() + "\n"; + header += app->help(); + return header; +} + +} // namespace FailureMessage + +namespace detail { +/// This class is simply to allow tests access to App's protected functions +struct AppFriend { + + /// Wrap _parse_short, perfectly forward arguments and return + template <typename... Args> + static auto parse_arg(App *app, Args &&... args) -> + typename std::result_of<decltype (&App::_parse_arg)(App, Args...)>::type { + return app->_parse_arg(std::forward<Args>(args)...); + } + + /// Wrap _parse_subcommand, perfectly forward arguments and return + template <typename... Args> + static auto parse_subcommand(App *app, Args &&... args) -> + typename std::result_of<decltype (&App::_parse_subcommand)(App, Args...)>::type { + return app->_parse_subcommand(std::forward<Args>(args)...); + } +}; +} // namespace detail + +} // namespace CLI diff --git a/packages/CLI11/include/CLI/CLI.hpp b/packages/CLI11/include/CLI/CLI.hpp new file mode 100644 index 0000000000000000000000000000000000000000..53a0cef230346bb583355c02d4c8b0de4ee077d4 --- /dev/null +++ b/packages/CLI11/include/CLI/CLI.hpp @@ -0,0 +1,25 @@ +#pragma once + +// Distributed under the 3-Clause BSD License. See accompanying +// file LICENSE or https://github.com/CLIUtils/CLI11 for details. + +// CLI Library includes +// Order is important for combiner script + +#include "CLI/Version.hpp" + +#include "CLI/StringTools.hpp" + +#include "CLI/Error.hpp" + +#include "CLI/TypeTools.hpp" + +#include "CLI/Split.hpp" + +#include "CLI/Ini.hpp" + +#include "CLI/Validators.hpp" + +#include "CLI/Option.hpp" + +#include "CLI/App.hpp" diff --git a/packages/CLI11/include/CLI/Error.hpp b/packages/CLI11/include/CLI/Error.hpp new file mode 100644 index 0000000000000000000000000000000000000000..bd47806b038e7992bacfc2abc5739e43b0309f2f --- /dev/null +++ b/packages/CLI11/include/CLI/Error.hpp @@ -0,0 +1,284 @@ +#pragma once + +// Distributed under the 3-Clause BSD License. See accompanying +// file LICENSE or https://github.com/CLIUtils/CLI11 for details. + +#include <exception> +#include <stdexcept> +#include <string> +#include <utility> + +// CLI library includes +#include "CLI/StringTools.hpp" + +namespace CLI { + +// Use one of these on all error classes +#define CLI11_ERROR_DEF(parent, name) \ + protected: \ + name(std::string name, std::string msg, int exit_code) : parent(std::move(name), std::move(msg), exit_code) {} \ + name(std::string name, std::string msg, ExitCodes exit_code) \ + : parent(std::move(name), std::move(msg), exit_code) {} \ + \ + public: \ + name(std::string msg, ExitCodes exit_code) : parent(#name, std::move(msg), exit_code) {} \ + name(std::string msg, int exit_code) : parent(#name, std::move(msg), exit_code) {} + +// This is added after the one above if a class is used directly and builds its own message +#define CLI11_ERROR_SIMPLE(name) \ + name(std::string msg) : name(#name, msg, ExitCodes::name) {} + +/// These codes are part of every error in CLI. They can be obtained from e using e.exit_code or as a quick shortcut, +/// int values from e.get_error_code(). +enum class ExitCodes { + Success = 0, + IncorrectConstruction = 100, + BadNameString, + OptionAlreadyAdded, + FileError, + ConversionError, + ValidationError, + RequiredError, + RequiresError, + ExcludesError, + ExtrasError, + INIError, + InvalidError, + HorribleError, + OptionNotFound, + ArgumentMismatch, + BaseClass = 127 +}; + +// Error definitions + +/// @defgroup error_group Errors +/// @brief Errors thrown by CLI11 +/// +/// These are the errors that can be thrown. Some of them, like CLI::Success, are not really errors. +/// @{ + +/// All errors derive from this one +class Error : public std::runtime_error { + int exit_code; + std::string name{"Error"}; + + public: + int get_exit_code() const { return exit_code; } + + std::string get_name() const { return name; } + + Error(std::string name, std::string msg, int exit_code = static_cast<int>(ExitCodes::BaseClass)) + : runtime_error(msg), exit_code(exit_code), name(std::move(name)) {} + + Error(std::string name, std::string msg, ExitCodes exit_code) : Error(name, msg, static_cast<int>(exit_code)) {} +}; + +// Note: Using Error::Error constructors does not work on GCC 4.7 + +/// Construction errors (not in parsing) +class ConstructionError : public Error { + CLI11_ERROR_DEF(Error, ConstructionError) +}; + +/// Thrown when an option is set to conflicting values (non-vector and multi args, for example) +class IncorrectConstruction : public ConstructionError { + CLI11_ERROR_DEF(ConstructionError, IncorrectConstruction) + CLI11_ERROR_SIMPLE(IncorrectConstruction) + static IncorrectConstruction PositionalFlag(std::string name) { + return IncorrectConstruction(name + ": Flags cannot be positional"); + } + static IncorrectConstruction Set0Opt(std::string name) { + return IncorrectConstruction(name + ": Cannot set 0 expected, use a flag instead"); + } + static IncorrectConstruction ChangeNotVector(std::string name) { + return IncorrectConstruction(name + ": You can only change the expected arguments for vectors"); + } + static IncorrectConstruction AfterMultiOpt(std::string name) { + return IncorrectConstruction( + name + ": You can't change expected arguments after you've changed the multi option policy!"); + } + static IncorrectConstruction MissingOption(std::string name) { + return IncorrectConstruction("Option " + name + " is not defined"); + } + static IncorrectConstruction MultiOptionPolicy(std::string name) { + return IncorrectConstruction(name + ": multi_option_policy only works for flags and single value options"); + } +}; + +/// Thrown on construction of a bad name +class BadNameString : public ConstructionError { + CLI11_ERROR_DEF(ConstructionError, BadNameString) + CLI11_ERROR_SIMPLE(BadNameString) + static BadNameString OneCharName(std::string name) { return BadNameString("Invalid one char name: " + name); } + static BadNameString BadLongName(std::string name) { return BadNameString("Bad long name: " + name); } + static BadNameString DashesOnly(std::string name) { + return BadNameString("Must have a name, not just dashes: " + name); + } + static BadNameString MultiPositionalNames(std::string name) { + return BadNameString("Only one positional name allowed, remove: " + name); + } +}; + +/// Thrown when an option already exists +class OptionAlreadyAdded : public ConstructionError { + CLI11_ERROR_DEF(ConstructionError, OptionAlreadyAdded) + OptionAlreadyAdded(std::string name) + : OptionAlreadyAdded(name + " is already added", ExitCodes::OptionAlreadyAdded) {} + static OptionAlreadyAdded Requires(std::string name, std::string other) { + return OptionAlreadyAdded(name + " requires " + other, ExitCodes::OptionAlreadyAdded); + } + static OptionAlreadyAdded Excludes(std::string name, std::string other) { + return OptionAlreadyAdded(name + " excludes " + other, ExitCodes::OptionAlreadyAdded); + } +}; + +// Parsing errors + +/// Anything that can error in Parse +class ParseError : public Error { + CLI11_ERROR_DEF(Error, ParseError) +}; + +// Not really "errors" + +/// This is a successful completion on parsing, supposed to exit +class Success : public ParseError { + CLI11_ERROR_DEF(ParseError, Success) + Success() : Success("Successfully completed, should be caught and quit", ExitCodes::Success) {} +}; + +/// -h or --help on command line +class CallForHelp : public ParseError { + CLI11_ERROR_DEF(ParseError, CallForHelp) + CallForHelp() : CallForHelp("This should be caught in your main function, see examples", ExitCodes::Success) {} +}; + +/// Does not output a diagnostic in CLI11_PARSE, but allows to return from main() with a specific error code. +class RuntimeError : public ParseError { + CLI11_ERROR_DEF(ParseError, RuntimeError) + RuntimeError(int exit_code = 1) : RuntimeError("Runtime error", exit_code) {} +}; + +/// Thrown when parsing an INI file and it is missing +class FileError : public ParseError { + CLI11_ERROR_DEF(ParseError, FileError) + CLI11_ERROR_SIMPLE(FileError) + static FileError Missing(std::string name) { return FileError(name + " was not readable (missing?)"); } +}; + +/// Thrown when conversion call back fails, such as when an int fails to coerce to a string +class ConversionError : public ParseError { + CLI11_ERROR_DEF(ParseError, ConversionError) + CLI11_ERROR_SIMPLE(ConversionError) + ConversionError(std::string member, std::string name) + : ConversionError("The value " + member + " is not an allowed value for " + name) {} + ConversionError(std::string name, std::vector<std::string> results) + : ConversionError("Could not convert: " + name + " = " + detail::join(results)) {} + static ConversionError TooManyInputsFlag(std::string name) { + return ConversionError(name + ": too many inputs for a flag"); + } + static ConversionError TrueFalse(std::string name) { + return ConversionError(name + ": Should be true/false or a number"); + } +}; + +/// Thrown when validation of results fails +class ValidationError : public ParseError { + CLI11_ERROR_DEF(ParseError, ValidationError) + CLI11_ERROR_SIMPLE(ValidationError) + ValidationError(std::string name, std::string msg) : ValidationError(name + ": " + msg) {} +}; + +/// Thrown when a required option is missing +class RequiredError : public ParseError { + CLI11_ERROR_DEF(ParseError, RequiredError) + RequiredError(std::string name) : RequiredError(name + " is required", ExitCodes::RequiredError) {} + static RequiredError Subcommand(size_t min_subcom) { + if(min_subcom == 1) + return RequiredError("A subcommand"); + else + return RequiredError("Requires at least " + std::to_string(min_subcom) + " subcommands", + ExitCodes::RequiredError); + } +}; + +/// Thrown when the wrong number of arguments has been received +class ArgumentMismatch : public ParseError { + CLI11_ERROR_DEF(ParseError, ArgumentMismatch) + CLI11_ERROR_SIMPLE(ArgumentMismatch) + ArgumentMismatch(std::string name, int expected, size_t recieved) + : ArgumentMismatch(expected > 0 ? ("Expected exactly " + std::to_string(expected) + " arguments to " + name + + ", got " + std::to_string(recieved)) + : ("Expected at least " + std::to_string(-expected) + " arguments to " + name + + ", got " + std::to_string(recieved)), + ExitCodes::ArgumentMismatch) {} + + static ArgumentMismatch AtLeast(std::string name, int num) { + return ArgumentMismatch(name + ": At least " + std::to_string(num) + " required"); + } + static ArgumentMismatch TypedAtLeast(std::string name, int num, std::string type) { + return ArgumentMismatch(name + ": " + std::to_string(num) + " required " + type + " missing"); + } +}; + +/// Thrown when a requires option is missing +class RequiresError : public ParseError { + CLI11_ERROR_DEF(ParseError, RequiresError) + RequiresError(std::string curname, std::string subname) + : RequiresError(curname + " requires " + subname, ExitCodes::RequiresError) {} +}; + +/// Thrown when an excludes option is present +class ExcludesError : public ParseError { + CLI11_ERROR_DEF(ParseError, ExcludesError) + ExcludesError(std::string curname, std::string subname) + : ExcludesError(curname + " excludes " + subname, ExitCodes::ExcludesError) {} +}; + +/// Thrown when too many positionals or options are found +class ExtrasError : public ParseError { + CLI11_ERROR_DEF(ParseError, ExtrasError) + ExtrasError(std::vector<std::string> args) + : ExtrasError((args.size() > 1 ? "The following arguments were not expected: " + : "The following argument was not expected: ") + + detail::rjoin(args, " "), + ExitCodes::ExtrasError) {} +}; + +/// Thrown when extra values are found in an INI file +class INIError : public ParseError { + CLI11_ERROR_DEF(ParseError, INIError) + CLI11_ERROR_SIMPLE(INIError) + static INIError Extras(std::string item) { return INIError("INI was not able to parse " + item); } + static INIError NotConfigurable(std::string item) { + return INIError(item + ": This option is not allowed in a configuration file"); + } +}; + +/// Thrown when validation fails before parsing +class InvalidError : public ParseError { + CLI11_ERROR_DEF(ParseError, InvalidError) + InvalidError(std::string name) + : InvalidError(name + ": Too many positional arguments with unlimited expected args", ExitCodes::InvalidError) { + } +}; + +/// This is just a safety check to verify selection and parsing match - you should not ever see it +/// Strings are directly added to this error, but again, it should never be seen. +class HorribleError : public ParseError { + CLI11_ERROR_DEF(ParseError, HorribleError) + CLI11_ERROR_SIMPLE(HorribleError) +}; + +// After parsing + +/// Thrown when counting a non-existent option +class OptionNotFound : public Error { + CLI11_ERROR_DEF(Error, OptionNotFound) + OptionNotFound(std::string name) : OptionNotFound(name + " not found", ExitCodes::OptionNotFound) {} +}; + +/// @} + +} // namespace CLI diff --git a/packages/CLI11/include/CLI/Ini.hpp b/packages/CLI11/include/CLI/Ini.hpp new file mode 100644 index 0000000000000000000000000000000000000000..f9999fff39401f6c73fa6f415cc23ebebb377106 --- /dev/null +++ b/packages/CLI11/include/CLI/Ini.hpp @@ -0,0 +1,115 @@ +#pragma once + +// Distributed under the 3-Clause BSD License. See accompanying +// file LICENSE or https://github.com/CLIUtils/CLI11 for details. + +#include <algorithm> +#include <fstream> +#include <iostream> +#include <string> + +#include "CLI/StringTools.hpp" + +namespace CLI { +namespace detail { + +inline std::string inijoin(std::vector<std::string> args) { + std::ostringstream s; + size_t start = 0; + for(const auto &arg : args) { + if(start++ > 0) + s << " "; + + auto it = std::find_if(arg.begin(), arg.end(), [](char ch) { return std::isspace<char>(ch, std::locale()); }); + if(it == arg.end()) + s << arg; + else if(arg.find(R"(")") == std::string::npos) + s << R"(")" << arg << R"(")"; + else + s << R"(')" << arg << R"(')"; + } + + return s.str(); +} + +struct ini_ret_t { + /// This is the full name with dots + std::string fullname; + + /// Listing of inputs + std::vector<std::string> inputs; + + /// Current parent level + size_t level = 0; + + /// Return parent or empty string, based on level + /// + /// Level 0, a.b.c would return a + /// Level 1, a.b.c could return b + std::string parent() const { + std::vector<std::string> plist = detail::split(fullname, '.'); + if(plist.size() > (level + 1)) + return plist[level]; + else + return ""; + } + + /// Return name + std::string name() const { + std::vector<std::string> plist = detail::split(fullname, '.'); + return plist.at(plist.size() - 1); + } +}; + +/// Internal parsing function +inline std::vector<ini_ret_t> parse_ini(std::istream &input) { + std::string name, line; + std::string section = "default"; + + std::vector<ini_ret_t> output; + + while(getline(input, line)) { + std::vector<std::string> items; + + detail::trim(line); + size_t len = line.length(); + if(len > 1 && line[0] == '[' && line[len - 1] == ']') { + section = line.substr(1, len - 2); + } else if(len > 0 && line[0] != ';') { + output.emplace_back(); + ini_ret_t &out = output.back(); + + // Find = in string, split and recombine + auto pos = line.find("="); + if(pos != std::string::npos) { + name = detail::trim_copy(line.substr(0, pos)); + std::string item = detail::trim_copy(line.substr(pos + 1)); + items = detail::split_up(item); + } else { + name = detail::trim_copy(line); + items = {"ON"}; + } + + if(detail::to_lower(section) == "default") + out.fullname = name; + else + out.fullname = section + "." + name; + + out.inputs.insert(std::end(out.inputs), std::begin(items), std::end(items)); + } + } + return output; +} + +/// Parse an INI file, throw an error (ParseError:INIParseError or FileError) on failure +inline std::vector<ini_ret_t> parse_ini(const std::string &name) { + + std::ifstream input{name}; + if(!input.good()) + throw FileError::Missing(name); + + return parse_ini(input); +} + +} // namespace detail +} // namespace CLI diff --git a/packages/CLI11/include/CLI/Option.hpp b/packages/CLI11/include/CLI/Option.hpp new file mode 100644 index 0000000000000000000000000000000000000000..f8222d3491ccad85b901524b1b155e0197c85714 --- /dev/null +++ b/packages/CLI11/include/CLI/Option.hpp @@ -0,0 +1,625 @@ +#pragma once + +// Distributed under the 3-Clause BSD License. See accompanying +// file LICENSE or https://github.com/CLIUtils/CLI11 for details. + +#include <algorithm> +#include <functional> +#include <memory> +#include <set> +#include <string> +#include <tuple> +#include <utility> +#include <vector> + +#include "CLI/Error.hpp" +#include "CLI/Split.hpp" +#include "CLI/StringTools.hpp" + +namespace CLI { + +using results_t = std::vector<std::string>; +using callback_t = std::function<bool(results_t)>; + +class Option; +class App; + +using Option_p = std::unique_ptr<Option>; + +enum class MultiOptionPolicy { Throw, TakeLast, TakeFirst, Join }; + +template <typename CRTP> class OptionBase { + friend App; + + protected: + /// The group membership + std::string group_{"Options"}; + + /// True if this is a required option + bool required_{false}; + + /// Ignore the case when matching (option, not value) + bool ignore_case_{false}; + + /// Allow this option to be given in a configuration file + bool configurable_{true}; + + /// Policy for multiple arguments when `expected_ == 1` (can be set on bool flags, too) + MultiOptionPolicy multi_option_policy_{MultiOptionPolicy::Throw}; + + template <typename T> void copy_to(T *other) const { + other->group(group_); + other->required(required_); + other->ignore_case(ignore_case_); + other->configurable(configurable_); + other->multi_option_policy(multi_option_policy_); + } + + public: + // setters + + /// Changes the group membership + CRTP *group(std::string name) { + group_ = name; + return static_cast<CRTP *>(this); + ; + } + + /// Set the option as required + CRTP *required(bool value = true) { + required_ = value; + return static_cast<CRTP *>(this); + } + + /// Support Plumbum term + CRTP *mandatory(bool value = true) { return required(value); } + + // Getters + + /// Get the group of this option + const std::string &get_group() const { return group_; } + + /// True if this is a required option + bool get_required() const { return required_; } + + /// The status of ignore case + bool get_ignore_case() const { return ignore_case_; } + + /// The status of configurable + bool get_configurable() const { return configurable_; } + + /// The status of the multi option policy + MultiOptionPolicy get_multi_option_policy() const { return multi_option_policy_; } + + // Shortcuts for multi option policy + + /// Set the multi option policy to take last + CRTP *take_last() { + auto self = static_cast<CRTP *>(this); + self->multi_option_policy(MultiOptionPolicy::TakeLast); + return self; + } + + /// Set the multi option policy to take last + CRTP *take_first() { + auto self = static_cast<CRTP *>(this); + self->multi_option_policy(MultiOptionPolicy::TakeFirst); + return self; + } + + /// Set the multi option policy to take last + CRTP *join() { + auto self = static_cast<CRTP *>(this); + self->multi_option_policy(MultiOptionPolicy::Join); + return self; + } + + /// Allow in a configuration file + CRTP *configurable(bool value = true) { + configurable_ = value; + return static_cast<CRTP *>(this); + } +}; + +class OptionDefaults : public OptionBase<OptionDefaults> { + public: + OptionDefaults() = default; + + // Methods here need a different implementation if they are Option vs. OptionDefault + + /// Take the last argument if given multiple times + OptionDefaults *multi_option_policy(MultiOptionPolicy value = MultiOptionPolicy::Throw) { + multi_option_policy_ = value; + return this; + } + + /// Ignore the case of the option name + OptionDefaults *ignore_case(bool value = true) { + ignore_case_ = value; + return this; + } +}; + +class Option : public OptionBase<Option> { + friend App; + + protected: + /// @name Names + ///@{ + + /// A list of the short names (`-a`) without the leading dashes + std::vector<std::string> snames_; + + /// A list of the long names (`--a`) without the leading dashes + std::vector<std::string> lnames_; + + /// A positional name + std::string pname_; + + /// If given, check the environment for this option + std::string envname_; + + ///@} + /// @name Help + ///@{ + + /// The description for help strings + std::string description_; + + /// A human readable default value, usually only set if default is true in creation + std::string defaultval_; + + /// A human readable type value, set when App creates this + std::string typeval_; + + /// True if this option has a default + bool default_{false}; + + ///@} + /// @name Configuration + ///@{ + + /// The number of expected values, 0 for flag, -1 for unlimited vector + int expected_{1}; + + /// A private setting to allow args to not be able to accept incorrect expected values + bool changeable_{false}; + + /// A list of validators to run on each value parsed + std::vector<std::function<std::string(std::string &)>> validators_; + + /// A list of options that are required with this option + std::set<Option *> requires_; + + /// A list of options that are excluded with this option + std::set<Option *> excludes_; + + ///@} + /// @name Other + ///@{ + + /// Remember the parent app + App *parent_; + + /// Options store a callback to do all the work + callback_t callback_; + + ///@} + /// @name Parsing results + ///@{ + + /// Results of parsing + results_t results_; + + /// Whether the callback has run (needed for INI parsing) + bool callback_run_{false}; + + ///@} + + /// Making an option by hand is not defined, it must be made by the App class + Option(std::string name, + std::string description = "", + std::function<bool(results_t)> callback = [](results_t) { return true; }, + bool default_ = true, + App *parent = nullptr) + : description_(std::move(description)), default_(default_), parent_(parent), callback_(std::move(callback)) { + std::tie(snames_, lnames_, pname_) = detail::get_names(detail::split_names(name)); + } + + public: + /// @name Basic + ///@{ + + /// Count the total number of times an option was passed + size_t count() const { return results_.size(); } + + /// This class is true if option is passed. + operator bool() const { return count() > 0; } + + /// Clear the parsed results (mostly for testing) + void clear() { results_.clear(); } + + ///@} + /// @name Setting options + ///@{ + + /// Set the number of expected arguments (Flags bypass this) + Option *expected(int value) { + if(expected_ == value) + return this; + else if(value == 0) + throw IncorrectConstruction::Set0Opt(single_name()); + else if(!changeable_) + throw IncorrectConstruction::ChangeNotVector(single_name()); + else if(value != 1 && multi_option_policy_ != MultiOptionPolicy::Throw) + throw IncorrectConstruction::AfterMultiOpt(single_name()); + + expected_ = value; + return this; + } + + /// Adds a validator + Option *check(std::function<std::string(const std::string &)> validator) { + validators_.emplace_back(validator); + return this; + } + + /// Adds a validator-like function that can change result + Option *transform(std::function<std::string(std::string)> func) { + validators_.emplace_back([func](std::string &inout) { + try { + inout = func(inout); + } catch(const ValidationError &e) { + return std::string(e.what()); + } + return std::string(); + }); + return this; + } + + /// Sets required options + Option *needs(Option *opt) { + auto tup = requires_.insert(opt); + if(!tup.second) + throw OptionAlreadyAdded::Requires(get_name(), opt->get_name()); + return this; + } + + /// Can find a string if needed + template <typename T = App> Option *needs(std::string opt_name) { + for(const Option_p &opt : dynamic_cast<T *>(parent_)->options_) + if(opt.get() != this && opt->check_name(opt_name)) + return needs(opt.get()); + throw IncorrectConstruction::MissingOption(opt_name); + } + + /// Any number supported, any mix of string and Opt + template <typename A, typename B, typename... ARG> Option *needs(A opt, B opt1, ARG... args) { + needs(opt); + return needs(opt1, args...); + } + +#if __cplusplus <= 201703L + /// Sets required options \deprecated + Option *requires(Option *opt) { return needs(opt); } + + /// Can find a string if needed \deprecated + template <typename T = App> Option *requires(std::string opt_name) { return needs<T>(opt_name); } + + /// Any number supported, any mix of string and Opt \deprecated + template <typename A, typename B, typename... ARG> Option *requires(A opt, B opt1, ARG... args) { + needs(opt); + return needs(opt1, args...); + } +#endif + + /// Sets excluded options + Option *excludes(Option *opt) { + auto tup = excludes_.insert(opt); + if(!tup.second) + throw OptionAlreadyAdded::Excludes(get_name(), opt->get_name()); + return this; + } + + /// Can find a string if needed + template <typename T = App> Option *excludes(std::string opt_name) { + for(const Option_p &opt : dynamic_cast<T *>(parent_)->options_) + if(opt.get() != this && opt->check_name(opt_name)) + return excludes(opt.get()); + throw IncorrectConstruction::MissingOption(opt_name); + } + + /// Any number supported, any mix of string and Opt + template <typename A, typename B, typename... ARG> Option *excludes(A opt, B opt1, ARG... args) { + excludes(opt); + return excludes(opt1, args...); + } + + /// Sets environment variable to read if no option given + Option *envname(std::string name) { + envname_ = name; + return this; + } + + /// Ignore case + /// + /// The template hides the fact that we don't have the definition of App yet. + /// You are never expected to add an argument to the template here. + template <typename T = App> Option *ignore_case(bool value = true) { + ignore_case_ = value; + auto *parent = dynamic_cast<T *>(parent_); + + for(const Option_p &opt : parent->options_) + if(opt.get() != this && *opt == *this) + throw OptionAlreadyAdded(opt->get_name()); + + return this; + } + + /// Take the last argument if given multiple times + Option *multi_option_policy(MultiOptionPolicy value = MultiOptionPolicy::Throw) { + if(get_expected() != 0 && get_expected() != 1) + throw IncorrectConstruction::MultiOptionPolicy(single_name()); + multi_option_policy_ = value; + return this; + } + + ///@} + /// @name Accessors + ///@{ + + /// The number of arguments the option expects + int get_expected() const { return expected_; } + + /// True if this has a default value + int get_default() const { return default_; } + + /// True if the argument can be given directly + bool get_positional() const { return pname_.length() > 0; } + + /// True if option has at least one non-positional name + bool nonpositional() const { return (snames_.size() + lnames_.size()) > 0; } + + /// True if option has description + bool has_description() const { return description_.length() > 0; } + + /// Get the description + const std::string &get_description() const { return description_; } + + // Just the pname + std::string get_pname() const { return pname_; } + + ///@} + /// @name Help tools + ///@{ + + /// Gets a , sep list of names. Does not include the positional name if opt_only=true. + std::string get_name(bool opt_only = false) const { + std::vector<std::string> name_list; + if(!opt_only && pname_.length() > 0) + name_list.push_back(pname_); + for(const std::string &sname : snames_) + name_list.push_back("-" + sname); + for(const std::string &lname : lnames_) + name_list.push_back("--" + lname); + return detail::join(name_list); + } + + /// The name and any extras needed for positionals + std::string help_positional() const { + std::string out = pname_; + if(get_expected() > 1) + out = out + "(" + std::to_string(get_expected()) + "x)"; + else if(get_expected() == -1) + out = out + "..."; + out = get_required() ? out : "[" + out + "]"; + return out; + } + + /// The most discriptive name available + std::string single_name() const { + if(!lnames_.empty()) + return std::string("--") + lnames_[0]; + else if(!snames_.empty()) + return std::string("-") + snames_[0]; + else + return pname_; + } + + /// The first half of the help print, name plus default, etc. Setting opt_only to true avoids the positional name. + std::string help_name(bool opt_only = false) const { + std::stringstream out; + out << get_name(opt_only) << help_aftername(); + return out.str(); + } + + /// pname with type info + std::string help_pname() const { + std::stringstream out; + out << get_pname() << help_aftername(); + return out.str(); + } + + /// This is the part after the name is printed but before the description + std::string help_aftername() const { + std::stringstream out; + + if(get_expected() != 0) { + if(!typeval_.empty()) + out << " " << typeval_; + if(!defaultval_.empty()) + out << "=" << defaultval_; + if(get_expected() > 1) + out << " x " << get_expected(); + if(get_expected() == -1) + out << " ..."; + } + if(!envname_.empty()) + out << " (env:" << envname_ << ")"; + if(!requires_.empty()) { + out << " Requires:"; + for(const Option *opt : requires_) + out << " " << opt->get_name(); + } + if(!excludes_.empty()) { + out << " Excludes:"; + for(const Option *opt : excludes_) + out << " " << opt->get_name(); + } + return out.str(); + } + + ///@} + /// @name Parser tools + ///@{ + + /// Process the callback + void run_callback() { + + // Run the validators (can change the string) + if(!validators_.empty()) { + for(std::string &result : results_) + for(const std::function<std::string(std::string &)> &vali : validators_) { + std::string err_msg = vali(result); + if(!err_msg.empty()) + throw ValidationError(single_name(), err_msg); + } + } + + bool local_result; + + // Operation depends on the policy setting + if(multi_option_policy_ == MultiOptionPolicy::TakeLast) { + results_t partial_result = {results_.back()}; + local_result = !callback_(partial_result); + } else if(multi_option_policy_ == MultiOptionPolicy::TakeFirst) { + results_t partial_result = {results_.at(0)}; + local_result = !callback_(partial_result); + } else if(multi_option_policy_ == MultiOptionPolicy::Join) { + results_t partial_result = {detail::join(results_, "\n")}; + local_result = !callback_(partial_result); + } else { + if((expected_ > 0 && results_.size() != static_cast<size_t>(expected_)) || + (expected_ < 0 && results_.size() < static_cast<size_t>(-expected_))) + throw ArgumentMismatch(single_name(), expected_, results_.size()); + else + local_result = !callback_(results_); + } + + if(local_result) + throw ConversionError(get_name(), results_); + } + + /// If options share any of the same names, they are equal (not counting positional) + bool operator==(const Option &other) const { + for(const std::string &sname : snames_) + if(other.check_sname(sname)) + return true; + for(const std::string &lname : lnames_) + if(other.check_lname(lname)) + return true; + // We need to do the inverse, just in case we are ignore_case + for(const std::string &sname : other.snames_) + if(check_sname(sname)) + return true; + for(const std::string &lname : other.lnames_) + if(check_lname(lname)) + return true; + return false; + } + + /// Check a name. Requires "-" or "--" for short / long, supports positional name + bool check_name(std::string name) const { + + if(name.length() > 2 && name.substr(0, 2) == "--") + return check_lname(name.substr(2)); + else if(name.length() > 1 && name.substr(0, 1) == "-") + return check_sname(name.substr(1)); + else { + std::string local_pname = pname_; + if(ignore_case_) { + local_pname = detail::to_lower(local_pname); + name = detail::to_lower(name); + } + return name == local_pname; + } + } + + /// Requires "-" to be removed from string + bool check_sname(std::string name) const { + if(ignore_case_) { + name = detail::to_lower(name); + return std::find_if(std::begin(snames_), std::end(snames_), [&name](std::string local_sname) { + return detail::to_lower(local_sname) == name; + }) != std::end(snames_); + } else + return std::find(std::begin(snames_), std::end(snames_), name) != std::end(snames_); + } + + /// Requires "--" to be removed from string + bool check_lname(std::string name) const { + if(ignore_case_) { + name = detail::to_lower(name); + return std::find_if(std::begin(lnames_), std::end(lnames_), [&name](std::string local_sname) { + return detail::to_lower(local_sname) == name; + }) != std::end(lnames_); + } else + return std::find(std::begin(lnames_), std::end(lnames_), name) != std::end(lnames_); + } + + /// Puts a result at the end, unless last_ is set, in which case it just keeps the last one + void add_result(std::string s) { + results_.push_back(s); + callback_run_ = false; + } + + /// Get a copy of the results + std::vector<std::string> results() const { return results_; } + + /// See if the callback has been run already + bool get_callback_run() const { return callback_run_; } + + ///@} + /// @name Custom options + ///@{ + + /// Set a custom option, typestring, expected; locks changeable unless expected is -1 + void set_custom_option(std::string typeval, int expected = 1) { + typeval_ = typeval; + expected_ = expected; + if(expected == 0) + required_ = false; + changeable_ = expected < 0; + } + + /// Set the default value string representation + void set_default_str(std::string val) { defaultval_ = val; } + + /// Set the default value string representation and evaluate + void set_default_val(std::string val) { + set_default_str(val); + auto old_results = results_; + results_ = {val}; + run_callback(); + results_ = std::move(old_results); + } + + /// Set the type name displayed on this option + void set_type_name(std::string val) { typeval_ = val; } + + /// Get the typename for this option + std::string get_type_name() const { return typeval_; } + + ///@} + + protected: + /// @name App Helpers + ///@{ + /// Can print positional name detailed option if true + bool _has_help_positional() const { + return get_positional() && (has_description() || !requires_.empty() || !excludes_.empty()); + } + ///@} +}; + +} // namespace CLI diff --git a/packages/CLI11/include/CLI/Split.hpp b/packages/CLI11/include/CLI/Split.hpp new file mode 100644 index 0000000000000000000000000000000000000000..8a1666cbec44fe86d5762d9c35e7ae728349e7ef --- /dev/null +++ b/packages/CLI11/include/CLI/Split.hpp @@ -0,0 +1,90 @@ +#pragma once + +// Distributed under the 3-Clause BSD License. See accompanying +// file LICENSE or https://github.com/CLIUtils/CLI11 for details. + +#include <string> +#include <tuple> +#include <vector> + +#include "CLI/Error.hpp" +#include "CLI/StringTools.hpp" + +namespace CLI { +namespace detail { + +// Returns false if not a short option. Otherwise, sets opt name and rest and returns true +inline bool split_short(const std::string ¤t, std::string &name, std::string &rest) { + if(current.size() > 1 && current[0] == '-' && valid_first_char(current[1])) { + name = current.substr(1, 1); + rest = current.substr(2); + return true; + } else + return false; +} + +// Returns false if not a long option. Otherwise, sets opt name and other side of = and returns true +inline bool split_long(const std::string ¤t, std::string &name, std::string &value) { + if(current.size() > 2 && current.substr(0, 2) == "--" && valid_first_char(current[2])) { + auto loc = current.find("="); + if(loc != std::string::npos) { + name = current.substr(2, loc - 2); + value = current.substr(loc + 1); + } else { + name = current.substr(2); + value = ""; + } + return true; + } else + return false; +} + +// Splits a string into multiple long and short names +inline std::vector<std::string> split_names(std::string current) { + std::vector<std::string> output; + size_t val; + while((val = current.find(",")) != std::string::npos) { + output.push_back(trim_copy(current.substr(0, val))); + current = current.substr(val + 1); + } + output.push_back(trim_copy(current)); + return output; +} + +/// Get a vector of short names, one of long names, and a single name +inline std::tuple<std::vector<std::string>, std::vector<std::string>, std::string> +get_names(const std::vector<std::string> &input) { + + std::vector<std::string> short_names; + std::vector<std::string> long_names; + std::string pos_name; + + for(std::string name : input) { + if(name.length() == 0) + continue; + else if(name.length() > 1 && name[0] == '-' && name[1] != '-') { + if(name.length() == 2 && valid_first_char(name[1])) + short_names.emplace_back(1, name[1]); + else + throw BadNameString::OneCharName(name); + } else if(name.length() > 2 && name.substr(0, 2) == "--") { + name = name.substr(2); + if(valid_name_string(name)) + long_names.push_back(name); + else + throw BadNameString::BadLongName(name); + } else if(name == "-" || name == "--") { + throw BadNameString::DashesOnly(name); + } else { + if(pos_name.length() > 0) + throw BadNameString::MultiPositionalNames(name); + pos_name = name; + } + } + + return std::tuple<std::vector<std::string>, std::vector<std::string>, std::string>( + short_names, long_names, pos_name); +} + +} // namespace detail +} // namespace CLI diff --git a/packages/CLI11/include/CLI/StringTools.hpp b/packages/CLI11/include/CLI/StringTools.hpp new file mode 100644 index 0000000000000000000000000000000000000000..ded9eaa6cce671518eff662f2aa50c53f1432f2e --- /dev/null +++ b/packages/CLI11/include/CLI/StringTools.hpp @@ -0,0 +1,207 @@ +#pragma once + +// Distributed under the 3-Clause BSD License. See accompanying +// file LICENSE or https://github.com/CLIUtils/CLI11 for details. + +#include <algorithm> +#include <iomanip> +#include <locale> +#include <sstream> +#include <string> +#include <vector> +#include <type_traits> + +namespace CLI { +namespace detail { + +// Based on http://stackoverflow.com/questions/236129/split-a-string-in-c +/// Split a string by a delim +inline std::vector<std::string> split(const std::string &s, char delim) { + std::vector<std::string> elems; + // Check to see if empty string, give consistent result + if(s.empty()) + elems.emplace_back(""); + else { + std::stringstream ss; + ss.str(s); + std::string item; + while(std::getline(ss, item, delim)) { + elems.push_back(item); + } + } + return elems; +} + +/// Simple function to join a string +template <typename T> std::string join(const T &v, std::string delim = ",") { + std::ostringstream s; + size_t start = 0; + for(const auto &i : v) { + if(start++ > 0) + s << delim; + s << i; + } + return s.str(); +} + +/// Join a string in reverse order +template <typename T> std::string rjoin(const T &v, std::string delim = ",") { + std::ostringstream s; + for(size_t start = 0; start < v.size(); start++) { + if(start > 0) + s << delim; + s << v[v.size() - start - 1]; + } + return s.str(); +} + +// Based roughly on http://stackoverflow.com/questions/25829143/c-trim-whitespace-from-a-string + +/// Trim whitespace from left of string +inline std::string <rim(std::string &str) { + auto it = std::find_if(str.begin(), str.end(), [](char ch) { return !std::isspace<char>(ch, std::locale()); }); + str.erase(str.begin(), it); + return str; +} + +/// Trim anything from left of string +inline std::string <rim(std::string &str, const std::string &filter) { + auto it = std::find_if(str.begin(), str.end(), [&filter](char ch) { return filter.find(ch) == std::string::npos; }); + str.erase(str.begin(), it); + return str; +} + +/// Trim whitespace from right of string +inline std::string &rtrim(std::string &str) { + auto it = std::find_if(str.rbegin(), str.rend(), [](char ch) { return !std::isspace<char>(ch, std::locale()); }); + str.erase(it.base(), str.end()); + return str; +} + +/// Trim anything from right of string +inline std::string &rtrim(std::string &str, const std::string &filter) { + auto it = + std::find_if(str.rbegin(), str.rend(), [&filter](char ch) { return filter.find(ch) == std::string::npos; }); + str.erase(it.base(), str.end()); + return str; +} + +/// Trim whitespace from string +inline std::string &trim(std::string &str) { return ltrim(rtrim(str)); } + +/// Trim anything from string +inline std::string &trim(std::string &str, const std::string filter) { return ltrim(rtrim(str, filter), filter); } + +/// Make a copy of the string and then trim it +inline std::string trim_copy(const std::string &str) { + std::string s = str; + return trim(s); +} + +/// Make a copy of the string and then trim it, any filter string can be used (any char in string is filtered) +inline std::string trim_copy(const std::string &str, const std::string &filter) { + std::string s = str; + return trim(s, filter); +} +/// Print a two part "help" string +inline void format_help(std::stringstream &out, std::string name, std::string description, size_t wid) { + name = " " + name; + out << std::setw(static_cast<int>(wid)) << std::left << name; + if(!description.empty()) { + if(name.length() >= wid) + out << std::endl << std::setw(static_cast<int>(wid)) << ""; + out << description; + } + out << std::endl; +} + +/// Verify the first character of an option +template <typename T> bool valid_first_char(T c) { return std::isalpha(c, std::locale()) || c == '_'; } + +/// Verify following characters of an option +template <typename T> bool valid_later_char(T c) { + return std::isalnum(c, std::locale()) || c == '_' || c == '.' || c == '-'; +} + +/// Verify an option name +inline bool valid_name_string(const std::string &str) { + if(str.empty() || !valid_first_char(str[0])) + return false; + for(auto c : str.substr(1)) + if(!valid_later_char(c)) + return false; + return true; +} + +/// Return a lower case version of a string +inline std::string to_lower(std::string str) { + std::transform(std::begin(str), std::end(str), std::begin(str), [](const std::string::value_type &x) { + return std::tolower(x, std::locale()); + }); + return str; +} + +/// Split a string '"one two" "three"' into 'one two', 'three' +inline std::vector<std::string> split_up(std::string str) { + + std::vector<char> delims = {'\'', '\"'}; + auto find_ws = [](char ch) { return std::isspace<char>(ch, std::locale()); }; + trim(str); + + std::vector<std::string> output; + + while(!str.empty()) { + if(str[0] == '\'') { + auto end = str.find('\'', 1); + if(end != std::string::npos) { + output.push_back(str.substr(1, end - 1)); + str = str.substr(end + 1); + } else { + output.push_back(str.substr(1)); + str = ""; + } + } else if(str[0] == '\"') { + auto end = str.find('\"', 1); + if(end != std::string::npos) { + output.push_back(str.substr(1, end - 1)); + str = str.substr(end + 1); + } else { + output.push_back(str.substr(1)); + str = ""; + } + + } else { + auto it = std::find_if(std::begin(str), std::end(str), find_ws); + if(it != std::end(str)) { + std::string value = std::string(str.begin(), it); + output.push_back(value); + str = std::string(it, str.end()); + } else { + output.push_back(str); + str = ""; + } + } + trim(str); + } + + return output; +} + +/// Add a leader to the beginning of all new lines (nothing is added +/// at the start of the first line). `"; "` would be for ini files +/// +/// Can't use Regex, or this would be a subs. +inline std::string fix_newlines(std::string leader, std::string input) { + std::string::size_type n = 0; + while(n != std::string::npos && n < input.size()) { + n = input.find('\n', n); + if(n != std::string::npos) { + input = input.substr(0, n + 1) + leader + input.substr(n + 1); + n += leader.size(); + } + } + return input; +} + +} // namespace detail +} // namespace CLI diff --git a/packages/CLI11/include/CLI/Timer.hpp b/packages/CLI11/include/CLI/Timer.hpp new file mode 100644 index 0000000000000000000000000000000000000000..eb6054ccb0868529961d6c0221fb9501d37c82dc --- /dev/null +++ b/packages/CLI11/include/CLI/Timer.hpp @@ -0,0 +1,127 @@ +#pragma once + +// Distributed under the 3-Clause BSD License. See accompanying +// file LICENSE or https://github.com/CLIUtils/CLI11 for details. + +// On GCC < 4.8, the following define is often missing. Due to the +// fact that this library only uses sleep_for, this should be safe +#if defined(__GNUC__) && !defined(__clang__) && __GNUC__ < 5 && __GNUC_MINOR__ < 8 +#define _GLIBCXX_USE_NANOSLEEP +#endif + +#include <chrono> +#include <functional> +#include <iostream> +#include <string> +#include <utility> + +namespace CLI { + +class Timer { + protected: + /// This is a typedef to make clocks easier to use + using clock = std::chrono::steady_clock; + + /// This typedef is for points in time + using time_point = std::chrono::time_point<clock>; + + /// This is the type of a printing function, you can make your own + using time_print_t = std::function<std::string(std::string, std::string)>; + + /// This is the title of the timer + std::string title_; + + /// This is the function that is used to format most of the timing message + time_print_t time_print_; + + /// This is the starting point (when the timer was created) + time_point start_; + + /// This is the number of times cycles (print divides by this number) + size_t cycles{1}; + + public: + /// Standard print function, this one is set by default + static std::string Simple(std::string title, std::string time) { return title + ": " + time; } + + /// This is a fancy print function with --- headers + static std::string Big(std::string title, std::string time) { + return std::string("-----------------------------------------\n") + "| " + title + " | Time = " + time + "\n" + + "-----------------------------------------"; + } + + public: + /// Standard constructor, can set title and print function + Timer(std::string title = "Timer", time_print_t time_print = Simple) + : title_(std::move(title)), time_print_(std::move(time_print)), start_(clock::now()) {} + + /// Time a function by running it multiple times. Target time is the len to target. + std::string time_it(std::function<void()> f, double target_time = 1) { + time_point start = start_; + double total_time; + + start_ = clock::now(); + size_t n = 0; + do { + f(); + std::chrono::duration<double> elapsed = clock::now() - start_; + total_time = elapsed.count(); + } while(n++ < 100 && total_time < target_time); + + std::string out = make_time_str(total_time / n) + " for " + std::to_string(n) + " tries"; + start_ = start; + return out; + } + + /// This formats the numerical value for the time string + std::string make_time_str() const { + time_point stop = clock::now(); + std::chrono::duration<double> elapsed = stop - start_; + double time = elapsed.count() / cycles; + return make_time_str(time); + } + + // LCOV_EXCL_START + std::string make_time_str(double time) const { + auto print_it = [](double x, std::string unit) { + char buffer[50]; + std::snprintf(buffer, 50, "%.5g", x); + return buffer + std::string(" ") + unit; + }; + + if(time < .000001) + return print_it(time * 1000000000, "ns"); + else if(time < .001) + return print_it(time * 1000000, "us"); + else if(time < 1) + return print_it(time * 1000, "ms"); + else + return print_it(time, "s"); + } + // LCOV_EXCL_END + + /// This is the main function, it creates a string + std::string to_string() const { return time_print_(title_, make_time_str()); } + + /// Division sets the number of cycles to divide by (no graphical change) + Timer &operator/(size_t val) { + cycles = val; + return *this; + } +}; + +/// This class prints out the time upon destruction +class AutoTimer : public Timer { + public: + /// Reimplementing the constructor is required in GCC 4.7 + AutoTimer(std::string title = "Timer", time_print_t time_print = Simple) : Timer(title, time_print) {} + // GCC 4.7 does not support using inheriting constructors. + + /// This desctructor prints the string + ~AutoTimer() { std::cout << to_string() << std::endl; } +}; + +} // namespace CLI + +/// This prints out the time if shifted into a std::cout like stream. +inline std::ostream &operator<<(std::ostream &in, const CLI::Timer &timer) { return in << timer.to_string(); } diff --git a/packages/CLI11/include/CLI/TypeTools.hpp b/packages/CLI11/include/CLI/TypeTools.hpp new file mode 100644 index 0000000000000000000000000000000000000000..fecdbafd29d6214b54c71495ec144c3df44ea20c --- /dev/null +++ b/packages/CLI11/include/CLI/TypeTools.hpp @@ -0,0 +1,156 @@ +#pragma once + +// Distributed under the 3-Clause BSD License. See accompanying +// file LICENSE or https://github.com/CLIUtils/CLI11 for details. + +#include <exception> +#include <string> +#include <type_traits> +#include <vector> + +namespace CLI { + +// Type tools + +// We could check to see if C++14 is being used, but it does not hurt to redefine this +// (even Google does this: https://github.com/google/skia/blob/master/include/private/SkTLogic.h) +// It is not in the std namespace anyway, so no harm done. + +template <bool B, class T = void> using enable_if_t = typename std::enable_if<B, T>::type; + +template <typename T> struct is_vector { static const bool value = false; }; + +template <class T, class A> struct is_vector<std::vector<T, A>> { static bool const value = true; }; + +template <typename T> struct is_bool { static const bool value = false; }; + +template <> struct is_bool<bool> { static bool const value = true; }; + +namespace detail { +// Based generally on https://rmf.io/cxx11/almost-static-if +/// Simple empty scoped class +enum class enabler {}; + +/// An instance to use in EnableIf +constexpr enabler dummy = {}; + +// Type name print + +/// Was going to be based on +/// http://stackoverflow.com/questions/1055452/c-get-name-of-type-in-template +/// But this is cleaner and works better in this case + +template <typename T, + enable_if_t<std::is_integral<T>::value && std::is_signed<T>::value, detail::enabler> = detail::dummy> +constexpr const char *type_name() { + return "INT"; +} + +template <typename T, + enable_if_t<std::is_integral<T>::value && std::is_unsigned<T>::value, detail::enabler> = detail::dummy> +constexpr const char *type_name() { + return "UINT"; +} + +template <typename T, enable_if_t<std::is_floating_point<T>::value, detail::enabler> = detail::dummy> +constexpr const char *type_name() { + return "FLOAT"; +} + +/// This one should not be used, since vector types print the internal type +template <typename T, enable_if_t<is_vector<T>::value, detail::enabler> = detail::dummy> +constexpr const char *type_name() { + return "VECTOR"; +} + +template <typename T, + enable_if_t<!std::is_floating_point<T>::value && !std::is_integral<T>::value && !is_vector<T>::value, + detail::enabler> = detail::dummy> +constexpr const char *type_name() { + return "TEXT"; +} + +// Lexical cast + +/// Signed integers / enums +template <typename T, + enable_if_t<(std::is_integral<T>::value && std::is_signed<T>::value) || std::is_enum<T>::value, + detail::enabler> = detail::dummy> +bool lexical_cast(std::string input, T &output) { + try { + size_t n = 0; + long long output_ll = std::stoll(input, &n, 0); + output = static_cast<T>(output_ll); + return n == input.size() && static_cast<long long>(output) == output_ll; + } catch(const std::invalid_argument &) { + return false; + } catch(const std::out_of_range &) { + return false; + } +} + +/// Unsigned integers +template <typename T, + enable_if_t<std::is_integral<T>::value && std::is_unsigned<T>::value, detail::enabler> = detail::dummy> +bool lexical_cast(std::string input, T &output) { + if(!input.empty() && input.front() == '-') + return false; // std::stoull happily converts negative values to junk without any errors. + + try { + size_t n = 0; + unsigned long long output_ll = std::stoull(input, &n, 0); + output = static_cast<T>(output_ll); + return n == input.size() && static_cast<unsigned long long>(output) == output_ll; + } catch(const std::invalid_argument &) { + return false; + } catch(const std::out_of_range &) { + return false; + } +} + +/// Floats +template <typename T, enable_if_t<std::is_floating_point<T>::value, detail::enabler> = detail::dummy> +bool lexical_cast(std::string input, T &output) { + try { + size_t n = 0; + output = static_cast<T>(std::stold(input, &n)); + return n == input.size(); + } catch(const std::invalid_argument &) { + return false; + } catch(const std::out_of_range &) { + return false; + } +} + +/// String and similar +template <typename T, + enable_if_t<!std::is_floating_point<T>::value && !std::is_integral<T>::value && !std::is_enum<T>::value && + std::is_assignable<T &, std::string>::value, + detail::enabler> = detail::dummy> +bool lexical_cast(std::string input, T &output) { + output = input; + return true; +} + +/// Non-string parsable +template <typename T, + enable_if_t<!std::is_floating_point<T>::value && !std::is_integral<T>::value && !std::is_enum<T>::value && + !std::is_assignable<T &, std::string>::value, + detail::enabler> = detail::dummy> +bool lexical_cast(std::string input, T &output) { + +// On GCC 4.7, thread_local is not available, so this optimization +// is turned off (avoiding multiple initialisations on multiple usages +#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) && __GNUC__ == 4 && (__GNUC_MINOR__ < 8) + std::istringstream is; +#else + static thread_local std::istringstream is; +#endif + + is.str(input); + is >> output; + return !is.fail() && !is.rdbuf()->in_avail(); +} + +} // namespace detail +} // namespace CLI diff --git a/packages/CLI11/include/CLI/Validators.hpp b/packages/CLI11/include/CLI/Validators.hpp new file mode 100644 index 0000000000000000000000000000000000000000..f158f92782b8ab74bbf40b2e2a69b7deaad42a2d --- /dev/null +++ b/packages/CLI11/include/CLI/Validators.hpp @@ -0,0 +1,92 @@ +#pragma once + +// Distributed under the 3-Clause BSD License. See accompanying +// file LICENSE or https://github.com/CLIUtils/CLI11 for details. + +#include "CLI/TypeTools.hpp" + +#include <functional> +#include <iostream> +#include <string> + +// C standard library +// Only needed for existence checking +// Could be swapped for filesystem in C++17 +#include <sys/stat.h> +#include <sys/types.h> + +namespace CLI { + +/// @defgroup validator_group Validators +/// @brief Some validators that are provided +/// +/// These are simple `void(std::string&)` validators that are useful. They throw +/// a ValidationError if they fail (or the normally expected error if the cast fails) +/// @{ + +/// Check for an existing file +inline std::string ExistingFile(const std::string &filename) { + struct stat buffer; + bool exist = stat(filename.c_str(), &buffer) == 0; + bool is_dir = (buffer.st_mode & S_IFDIR) != 0; + if(!exist) { + return "File does not exist: " + filename; + } else if(is_dir) { + return "File is actually a directory: " + filename; + } + return std::string(); +} + +/// Check for an existing directory +inline std::string ExistingDirectory(const std::string &filename) { + struct stat buffer; + bool exist = stat(filename.c_str(), &buffer) == 0; + bool is_dir = (buffer.st_mode & S_IFDIR) != 0; + if(!exist) { + return "Directory does not exist: " + filename; + } else if(!is_dir) { + return "Directory is actually a file: " + filename; + } + return std::string(); +} + +/// Check for an existing path +inline std::string ExistingPath(const std::string &filename) { + struct stat buffer; + bool const exist = stat(filename.c_str(), &buffer) == 0; + if(!exist) { + return "Path does not exist: " + filename; + } + return std::string(); +} + +/// Check for a non-existing path +inline std::string NonexistentPath(const std::string &filename) { + struct stat buffer; + bool exist = stat(filename.c_str(), &buffer) == 0; + if(exist) { + return "Path already exists: " + filename; + } + return std::string(); +} + +/// Produce a range validator function +template <typename T> std::function<std::string(const std::string &)> Range(T min, T max) { + return [min, max](std::string input) { + T val; + detail::lexical_cast(input, val); + if(val < min || val > max) + return "Value " + input + " not in range " + std::to_string(min) + " to " + std::to_string(max); + + return std::string(); + }; +} + +/// Range of one value is 0 to value +template <typename T> std::function<std::string(const std::string &)> Range(T max) { + return Range(static_cast<T>(0), max); +} + +/// @} + +} // namespace CLI diff --git a/packages/CLI11/include/CLI/Version.hpp b/packages/CLI11/include/CLI/Version.hpp new file mode 100644 index 0000000000000000000000000000000000000000..40abb162fb896294b4c8c3c929b787feba78981f --- /dev/null +++ b/packages/CLI11/include/CLI/Version.hpp @@ -0,0 +1,15 @@ +#pragma once + +// Distributed under the 3-Clause BSD License. See accompanying +// file LICENSE or https://github.com/CLIUtils/CLI11 for details. + +namespace CLI { + +// Note that all code in CLI11 must be in a namespace, even if it just a define. + +#define CLI11_VERSION_MAJOR 1 +#define CLI11_VERSION_MINOR 4 +#define CLI11_VERSION_PATCH 0 +#define CLI11_VERSION "1.4.0" + +} // namespace CLI diff --git a/packages/CLI11/scripts/MakeSingleHeader.py b/packages/CLI11/scripts/MakeSingleHeader.py new file mode 100755 index 0000000000000000000000000000000000000000..e6985beb1d8ff10752a5fb913945f0958ba45c9f --- /dev/null +++ b/packages/CLI11/scripts/MakeSingleHeader.py @@ -0,0 +1,66 @@ +#!/usr/bin/env python + +# Requires pathlib on python 2 + +from __future__ import print_function, unicode_literals + +import os +import re +import argparse +from subprocess import check_output, CalledProcessError + +includes_local = re.compile(r"""^#include "(.*)"$""", re.MULTILINE) +includes_system = re.compile(r"""^#include \<(.*)\>$""", re.MULTILINE) + +DIR = os.path.dirname(os.path.abspath(__file__)) # Path(__file__).resolve().parent +BDIR = os.path.join(os.path.dirname(DIR), 'include') # DIR.parent / 'include' + +print("Git directory:", DIR) + +try: + TAG = check_output(['git', 'describe', '--tags', '--always'], cwd=str(DIR)).decode("utf-8") +except CalledProcessError: + TAG = "A non-git source" + +def MakeHeader(out): + main_header = os.path.join(BDIR, 'CLI', 'CLI.hpp') + with open(main_header) as f: + header = f.read() + + include_files = includes_local.findall(header) + + headers = set() + output = '' + for inc in include_files: + with open(os.path.join(BDIR, inc)) as f: + inner = f.read() + headers |= set(includes_system.findall(inner)) + output += '\n// From {inc}\n\n'.format(inc=inc) + output += inner[inner.find('namespace'):] + + header_list = '\n'.join('#include <'+h+'>' for h in headers) + + output = '''\ +#pragma once + +// Distributed under the 3-Clause BSD License. See accompanying +// file LICENSE or https://github.com/CLIUtils/CLI11 for details. + +// This file was generated using MakeSingleHeader.py in CLI11/scripts +// from: {tag} +// This has the complete CLI library in one file. + +{header_list} +{output}'''.format(header_list=header_list, output=output, tag=TAG) + + with open(out, 'w') as f: + f.write(output) + + print("Created {out}".format(out=out)) + + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument("output", nargs='?', default=os.path.join(BDIR, 'CLI11.hpp')) + args = parser.parse_args() + MakeHeader(args.output) diff --git a/packages/CLI11/scripts/UpdateDownloadProj.py b/packages/CLI11/scripts/UpdateDownloadProj.py new file mode 100755 index 0000000000000000000000000000000000000000..c35743b61f67fa5a81f028177fee7a7c9eca9493 --- /dev/null +++ b/packages/CLI11/scripts/UpdateDownloadProj.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python + +from __future__ import print_function, division + +from plumbum import local, cli, FG +from plumbum.cmd import curl + +FILES = [ 'https://raw.githubusercontent.com/Crascit/DownloadProject/master/DownloadProject.cmake', + 'https://raw.githubusercontent.com/Crascit/DownloadProject/master/DownloadProject.CMakeLists.cmake.in'] + +DIR = local.path(__file__).dirname + +def download_file(path): + name = path.split('/')[-1] + (curl[path] > name) & FG + +class UpdateDownloadProj(cli.Application): + def main(self): + with local.cwd(DIR / '../cmake'): + for f in FILES: + download_file(f) + +if __name__ == "__main__": + UpdateDownloadProj() diff --git a/packages/CLI11/scripts/check_style.sh b/packages/CLI11/scripts/check_style.sh new file mode 100755 index 0000000000000000000000000000000000000000..3fe500ec60d64047cba9ae4deac09404fb11319d --- /dev/null +++ b/packages/CLI11/scripts/check_style.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env sh +set -evx + +clang-format --version + +git ls-files -- '*.cpp' '*.hpp' | xargs clang-format -i -style=file + +git diff --exit-code --color + +set +evx diff --git a/packages/CLI11/test_package/CMakeLists.txt b/packages/CLI11/test_package/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..48f6d9903248c09c1c897f5266dab257f42907e2 --- /dev/null +++ b/packages/CLI11/test_package/CMakeLists.txt @@ -0,0 +1,16 @@ +project(PackageTest CXX) +cmake_minimum_required(VERSION 3.1) + +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup() + +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_EXTENSIONS OFF) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +message(STATUS "${CMAKE_PREFIX_PATH}") + +find_package(CLI11 CONFIG REQUIRED) + +add_executable(example example.cpp) +target_link_libraries(example CLI11::CLI11) diff --git a/packages/CLI11/test_package/conanfile.py b/packages/CLI11/test_package/conanfile.py new file mode 100644 index 0000000000000000000000000000000000000000..0202a8a828e7578bbc0de4afef5bbe0c7728975a --- /dev/null +++ b/packages/CLI11/test_package/conanfile.py @@ -0,0 +1,19 @@ +from conans import ConanFile, CMake +import os + +class HelloTestConan(ConanFile): + settings = "os", "compiler", "build_type", "arch" + generators = "cmake" + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def imports(self): + self.copy("*.dll", dst="bin", src="bin") + self.copy("*.dylib*", dst="bin", src="lib") + + def test(self): + os.chdir("bin") + self.run(".%sexample" % os.sep) diff --git a/packages/CLI11/test_package/example.cpp b/packages/CLI11/test_package/example.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2dfa1d2fa344b6cfc76250e3461807c48d06f1be --- /dev/null +++ b/packages/CLI11/test_package/example.cpp @@ -0,0 +1,20 @@ +// This file is a "Hello, world!" CLI11 program + +#include "CLI/CLI.hpp" + +#include <iostream> + +int main(int argc, char **argv) { + + CLI::App app("Some nice discription"); + + int x = 0; + app.add_option("-x", x, "an integer value", true /* show default */); + + bool flag; + app.add_flag("-f,--flag", flag, "a flag option"); + + CLI11_PARSE(app, argc, argv); + + return 0; +} diff --git a/packages/CLI11/tests/.syntastic_cpp_config b/packages/CLI11/tests/.syntastic_cpp_config new file mode 100644 index 0000000000000000000000000000000000000000..67ad58301aee06c533ff5171e4e182f30fa4186f --- /dev/null +++ b/packages/CLI11/tests/.syntastic_cpp_config @@ -0,0 +1 @@ +- I../ build / googletest - src / googletest / include / -I../ build / googletest - src / googlemock / include / diff --git a/packages/CLI11/tests/AppTest.cpp b/packages/CLI11/tests/AppTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e53f9a13530a251a72f9a36973c5de306c83fcf9 --- /dev/null +++ b/packages/CLI11/tests/AppTest.cpp @@ -0,0 +1,1382 @@ +#include "app_helper.hpp" +#include <cstdlib> + +TEST_F(TApp, OneFlagShort) { + app.add_flag("-c,--count"); + args = {"-c"}; + run(); + EXPECT_EQ((size_t)1, app.count("-c")); + EXPECT_EQ((size_t)1, app.count("--count")); +} + +TEST_F(TApp, CountNonExist) { + app.add_flag("-c,--count"); + args = {"-c"}; + run(); + EXPECT_THROW(app.count("--nonexist"), CLI::OptionNotFound); +} + +TEST_F(TApp, OneFlagLong) { + app.add_flag("-c,--count"); + args = {"--count"}; + run(); + EXPECT_EQ((size_t)1, app.count("-c")); + EXPECT_EQ((size_t)1, app.count("--count")); +} + +TEST_F(TApp, DashedOptions) { + app.add_flag("-c"); + app.add_flag("--q"); + app.add_flag("--this,--that"); + + args = {"-c", "--q", "--this", "--that"}; + run(); + EXPECT_EQ((size_t)1, app.count("-c")); + EXPECT_EQ((size_t)1, app.count("--q")); + EXPECT_EQ((size_t)2, app.count("--this")); + EXPECT_EQ((size_t)2, app.count("--that")); +} + +TEST_F(TApp, OneFlagRef) { + int ref; + app.add_flag("-c,--count", ref); + args = {"--count"}; + run(); + EXPECT_EQ((size_t)1, app.count("-c")); + EXPECT_EQ((size_t)1, app.count("--count")); + EXPECT_EQ(1, ref); +} + +TEST_F(TApp, OneString) { + std::string str; + app.add_option("-s,--string", str); + args = {"--string", "mystring"}; + run(); + EXPECT_EQ((size_t)1, app.count("-s")); + EXPECT_EQ((size_t)1, app.count("--string")); + EXPECT_EQ(str, "mystring"); +} + +TEST_F(TApp, OneStringEqualVersion) { + std::string str; + app.add_option("-s,--string", str); + args = {"--string=mystring"}; + run(); + EXPECT_EQ((size_t)1, app.count("-s")); + EXPECT_EQ((size_t)1, app.count("--string")); + EXPECT_EQ(str, "mystring"); +} + +TEST_F(TApp, TogetherInt) { + int i; + app.add_option("-i,--int", i); + args = {"-i4"}; + run(); + EXPECT_EQ((size_t)1, app.count("--int")); + EXPECT_EQ((size_t)1, app.count("-i")); + EXPECT_EQ(i, 4); +} + +TEST_F(TApp, SepInt) { + int i; + app.add_option("-i,--int", i); + args = {"-i", "4"}; + run(); + EXPECT_EQ((size_t)1, app.count("--int")); + EXPECT_EQ((size_t)1, app.count("-i")); + EXPECT_EQ(i, 4); +} + +TEST_F(TApp, OneStringAgain) { + std::string str; + app.add_option("-s,--string", str); + args = {"--string", "mystring"}; + run(); + EXPECT_EQ((size_t)1, app.count("-s")); + EXPECT_EQ((size_t)1, app.count("--string")); + EXPECT_EQ(str, "mystring"); +} + +TEST_F(TApp, DefaultStringAgain) { + std::string str = "previous"; + app.add_option("-s,--string", str); + run(); + EXPECT_EQ((size_t)0, app.count("-s")); + EXPECT_EQ((size_t)0, app.count("--string")); + EXPECT_EQ(str, "previous"); +} + +TEST_F(TApp, DualOptions) { + + std::string str = "previous"; + std::vector<std::string> vstr = {"previous"}; + std::vector<std::string> ans = {"one", "two"}; + app.add_option("-s,--string", str); + app.add_option("-v,--vector", vstr); + + args = {"--vector=one", "--vector=two"}; + run(); + EXPECT_EQ(ans, vstr); + + args = {"--string=one", "--string=two"}; + EXPECT_THROW(run(), CLI::ArgumentMismatch); +} + +TEST_F(TApp, LotsOfFlags) { + + app.add_flag("-a"); + app.add_flag("-A"); + app.add_flag("-b"); + + args = {"-a", "-b", "-aA"}; + run(); + EXPECT_EQ((size_t)2, app.count("-a")); + EXPECT_EQ((size_t)1, app.count("-b")); + EXPECT_EQ((size_t)1, app.count("-A")); +} + +TEST_F(TApp, BoolAndIntFlags) { + + bool bflag; + int iflag; + unsigned int uflag; + + app.add_flag("-b", bflag); + app.add_flag("-i", iflag); + app.add_flag("-u", uflag); + + args = {"-b", "-i", "-u"}; + run(); + EXPECT_TRUE(bflag); + EXPECT_EQ(1, iflag); + EXPECT_EQ((unsigned int)1, uflag); + + app.reset(); + + args = {"-b", "-b"}; + EXPECT_NO_THROW(run()); + EXPECT_TRUE(bflag); + + app.reset(); + bflag = false; + + args = {"-iiiuu"}; + run(); + EXPECT_FALSE(bflag); + EXPECT_EQ(3, iflag); + EXPECT_EQ((unsigned int)2, uflag); +} + +TEST_F(TApp, BoolOnlyFlag) { + bool bflag; + app.add_flag("-b", bflag)->multi_option_policy(CLI::MultiOptionPolicy::Throw); + + args = {"-b"}; + EXPECT_NO_THROW(run()); + EXPECT_TRUE(bflag); + + app.reset(); + + args = {"-b", "-b"}; + EXPECT_THROW(run(), CLI::ConversionError); +} + +TEST_F(TApp, ShortOpts) { + + unsigned long long funnyint; + std::string someopt; + app.add_flag("-z", funnyint); + app.add_option("-y", someopt); + + args = { + "-zzyzyz", + }; + + run(); + + EXPECT_EQ((size_t)2, app.count("-z")); + EXPECT_EQ((size_t)1, app.count("-y")); + EXPECT_EQ((unsigned long long)2, funnyint); + EXPECT_EQ("zyz", someopt); +} + +TEST_F(TApp, DefaultOpts) { + + int i = 3; + std::string s = "HI"; + + app.add_option("-i,i", i, "", false); + app.add_option("-s,s", s, "", true); + + args = {"-i2", "9"}; + + run(); + + EXPECT_EQ((size_t)1, app.count("i")); + EXPECT_EQ((size_t)1, app.count("-s")); + EXPECT_EQ(2, i); + EXPECT_EQ("9", s); +} + +TEST_F(TApp, TakeLastOpt) { + + std::string str; + app.add_option("--str", str)->multi_option_policy(CLI::MultiOptionPolicy::TakeLast); + + args = {"--str=one", "--str=two"}; + + run(); + + EXPECT_EQ(str, "two"); +} + +TEST_F(TApp, TakeLastOpt2) { + + std::string str; + app.add_option("--str", str)->take_last(); + + args = {"--str=one", "--str=two"}; + + run(); + + EXPECT_EQ(str, "two"); +} + +TEST_F(TApp, TakeFirstOpt) { + + std::string str; + app.add_option("--str", str)->multi_option_policy(CLI::MultiOptionPolicy::TakeFirst); + + args = {"--str=one", "--str=two"}; + + run(); + + EXPECT_EQ(str, "one"); +} + +TEST_F(TApp, TakeFirstOpt2) { + + std::string str; + app.add_option("--str", str)->take_first(); + + args = {"--str=one", "--str=two"}; + + run(); + + EXPECT_EQ(str, "one"); +} + +TEST_F(TApp, JoinOpt) { + + std::string str; + app.add_option("--str", str)->multi_option_policy(CLI::MultiOptionPolicy::Join); + + args = {"--str=one", "--str=two"}; + + run(); + + EXPECT_EQ(str, "one\ntwo"); +} + +TEST_F(TApp, JoinOpt2) { + + std::string str; + app.add_option("--str", str)->join(); + + args = {"--str=one", "--str=two"}; + + run(); + + EXPECT_EQ(str, "one\ntwo"); +} + +TEST_F(TApp, MissingValueNonRequiredOpt) { + int count; + app.add_option("-c,--count", count); + + args = {"-c"}; + EXPECT_THROW(run(), CLI::ArgumentMismatch); + + app.reset(); + + args = {"--count"}; + EXPECT_THROW(run(), CLI::ArgumentMismatch); +} + +TEST_F(TApp, MissingValueMoreThan) { + std::vector<int> vals1; + std::vector<int> vals2; + app.add_option("-v", vals1)->expected(-2); + app.add_option("--vals", vals2)->expected(-2); + + args = {"-v", "2"}; + EXPECT_THROW(run(), CLI::ArgumentMismatch); + + app.reset(); + + args = {"--vals", "4"}; + EXPECT_THROW(run(), CLI::ArgumentMismatch); +} + +TEST_F(TApp, NotRequiredOptsSingle) { + + std::string str; + app.add_option("--str", str); + + args = {"--str"}; + + EXPECT_THROW(run(), CLI::ArgumentMismatch); +} + +TEST_F(TApp, NotRequiredOptsSingleShort) { + + std::string str; + app.add_option("-s", str); + + args = {"-s"}; + + EXPECT_THROW(run(), CLI::ArgumentMismatch); +} + +TEST_F(TApp, RequiredOptsSingle) { + + std::string str; + app.add_option("--str", str)->required(); + + args = {"--str"}; + + EXPECT_THROW(run(), CLI::ArgumentMismatch); +} + +TEST_F(TApp, RequiredOptsSingleShort) { + + std::string str; + app.add_option("-s", str)->required(); + + args = {"-s"}; + + EXPECT_THROW(run(), CLI::ArgumentMismatch); +} + +TEST_F(TApp, RequiredOptsDouble) { + + std::vector<std::string> strs; + app.add_option("--str", strs)->required()->expected(2); + + args = {"--str", "one"}; + + EXPECT_THROW(run(), CLI::ArgumentMismatch); + + app.reset(); + args = {"--str", "one", "two"}; + + run(); + + EXPECT_EQ(strs, std::vector<std::string>({"one", "two"})); +} + +TEST_F(TApp, RequiredOptsDoubleShort) { + + std::vector<std::string> strs; + app.add_option("-s", strs)->required()->expected(2); + + args = {"-s", "one"}; + + EXPECT_THROW(run(), CLI::ArgumentMismatch); + + app.reset(); + + args = {"-s", "one", "-s", "one", "-s", "one"}; + + EXPECT_THROW(run(), CLI::ArgumentMismatch); +} + +TEST_F(TApp, RequiredOptsDoubleNeg) { + std::vector<std::string> strs; + app.add_option("-s", strs)->required()->expected(-2); + + args = {"-s", "one"}; + + EXPECT_THROW(run(), CLI::ArgumentMismatch); + + app.reset(); + + args = {"-s", "one", "two", "-s", "three"}; + + EXPECT_NO_THROW(run()); + + EXPECT_EQ(strs, std::vector<std::string>({"one", "two", "three"})); + + app.reset(); + args = {"-s", "one", "two"}; + + EXPECT_NO_THROW(run()); + + EXPECT_EQ(strs, std::vector<std::string>({"one", "two"})); +} + +TEST_F(TApp, RequiredOptsUnlimited) { + + std::vector<std::string> strs; + app.add_option("--str", strs)->required(); + + args = {"--str"}; + EXPECT_THROW(run(), CLI::ArgumentMismatch); + + app.reset(); + args = {"--str", "one", "--str", "two"}; + run(); + EXPECT_EQ(strs, std::vector<std::string>({"one", "two"})); + + app.reset(); + args = {"--str", "one", "two"}; + run(); + EXPECT_EQ(strs, std::vector<std::string>({"one", "two"})); + + // It's better to feed a hungry option than to feed allow_extras + app.reset(); + app.allow_extras(); + run(); + EXPECT_EQ(strs, std::vector<std::string>({"one", "two"})); + EXPECT_EQ(app.remaining(), std::vector<std::string>({})); + + app.reset(); + app.allow_extras(false); + std::vector<std::string> remain; + app.add_option("positional", remain); + run(); + EXPECT_EQ(strs, std::vector<std::string>({"one"})); + EXPECT_EQ(remain, std::vector<std::string>({"two"})); +} + +TEST_F(TApp, RequiredOptsUnlimitedShort) { + + std::vector<std::string> strs; + app.add_option("-s", strs)->required(); + + args = {"-s"}; + EXPECT_THROW(run(), CLI::ArgumentMismatch); + + app.reset(); + args = {"-s", "one", "-s", "two"}; + run(); + EXPECT_EQ(strs, std::vector<std::string>({"one", "two"})); + + app.reset(); + args = {"-s", "one", "two"}; + run(); + EXPECT_EQ(strs, std::vector<std::string>({"one", "two"})); + + // It's better to feed a hungry option than to feed allow_extras + app.reset(); + app.allow_extras(); + run(); + EXPECT_EQ(strs, std::vector<std::string>({"one", "two"})); + EXPECT_EQ(app.remaining(), std::vector<std::string>({})); + + app.reset(); + app.allow_extras(false); + std::vector<std::string> remain; + app.add_option("positional", remain); + run(); + EXPECT_EQ(strs, std::vector<std::string>({"one"})); + EXPECT_EQ(remain, std::vector<std::string>({"two"})); +} + +TEST_F(TApp, RequireOptPriority) { + + std::vector<std::string> strs; + app.add_option("--str", strs)->required(); + std::vector<std::string> remain; + app.add_option("positional", remain)->expected(2); + + args = {"--str", "one", "two", "three"}; + run(); + + EXPECT_EQ(strs, std::vector<std::string>({"one"})); + EXPECT_EQ(remain, std::vector<std::string>({"two", "three"})); + + app.reset(); + args = {"two", "three", "--str", "one", "four"}; + run(); + + EXPECT_EQ(strs, std::vector<std::string>({"one", "four"})); + EXPECT_EQ(remain, std::vector<std::string>({"two", "three"})); +} + +TEST_F(TApp, RequireOptPriorityShort) { + + std::vector<std::string> strs; + app.add_option("-s", strs)->required(); + std::vector<std::string> remain; + app.add_option("positional", remain)->expected(2); + + args = {"-s", "one", "two", "three"}; + run(); + + EXPECT_EQ(strs, std::vector<std::string>({"one"})); + EXPECT_EQ(remain, std::vector<std::string>({"two", "three"})); + + app.reset(); + args = {"two", "three", "-s", "one", "four"}; + run(); + + EXPECT_EQ(strs, std::vector<std::string>({"one", "four"})); + EXPECT_EQ(remain, std::vector<std::string>({"two", "three"})); +} + +TEST_F(TApp, NotRequiedExpectedDouble) { + + std::vector<std::string> strs; + app.add_option("--str", strs)->expected(2); + + args = {"--str", "one"}; + + EXPECT_THROW(run(), CLI::ArgumentMismatch); +} + +TEST_F(TApp, NotRequiedExpectedDoubleShort) { + + std::vector<std::string> strs; + app.add_option("-s", strs)->expected(2); + + args = {"-s", "one"}; + + EXPECT_THROW(run(), CLI::ArgumentMismatch); +} + +TEST_F(TApp, EnumTest) { + enum Level : std::int32_t { High, Medium, Low }; + Level level = Level::Low; + app.add_option("--level", level); + + args = {"--level", "1"}; + run(); + EXPECT_EQ(level, Level::Medium); +} + +TEST_F(TApp, NewEnumTest) { + enum class Level2 : std::int32_t { High, Medium, Low }; + Level2 level = Level2::Low; + app.add_option("--level", level); + + args = {"--level", "1"}; + run(); + EXPECT_EQ(level, Level2::Medium); +} + +TEST_F(TApp, RequiredFlags) { + app.add_flag("-a")->required(); + app.add_flag("-b")->mandatory(); // Alternate term + + EXPECT_THROW(run(), CLI::RequiredError); + + app.reset(); + + args = {"-a"}; + EXPECT_THROW(run(), CLI::RequiredError); + + app.reset(); + args = {"-b"}; + EXPECT_THROW(run(), CLI::RequiredError); + + app.reset(); + args = {"-a", "-b"}; + run(); +} + +TEST_F(TApp, CallbackFlags) { + + int value = 0; + + auto func = [&value](size_t x) { value = x; }; + + app.add_flag_function("-v", func); + + run(); + EXPECT_EQ(value, 0); + + app.reset(); + args = {"-v"}; + run(); + EXPECT_EQ(value, 1); + + app.reset(); + args = {"-vv"}; + run(); + EXPECT_EQ(value, 2); + + EXPECT_THROW(app.add_flag_function("hi", func), CLI::IncorrectConstruction); +} + +#if __cplusplus >= 201402L +TEST_F(TApp, CallbackFlagsAuto) { + + int value = 0; + + auto func = [&value](size_t x) { value = x; }; + + app.add_flag("-v", func); + + run(); + EXPECT_EQ(value, 0); + + app.reset(); + args = {"-v"}; + run(); + EXPECT_EQ(value, 1); + + app.reset(); + args = {"-vv"}; + run(); + EXPECT_EQ(value, 2); + + EXPECT_THROW(app.add_flag("hi", func), CLI::IncorrectConstruction); +} +#endif + +TEST_F(TApp, Positionals) { + + std::string posit1; + std::string posit2; + app.add_option("posit1", posit1); + app.add_option("posit2", posit2); + + args = {"thing1", "thing2"}; + + run(); + + EXPECT_EQ((size_t)1, app.count("posit1")); + EXPECT_EQ((size_t)1, app.count("posit2")); + EXPECT_EQ("thing1", posit1); + EXPECT_EQ("thing2", posit2); +} + +TEST_F(TApp, ForcedPositional) { + std::vector<std::string> posit; + auto one = app.add_flag("--one"); + app.add_option("posit", posit); + + args = {"--one", "two", "three"}; + run(); + std::vector<std::string> answers1 = {"two", "three"}; + EXPECT_TRUE(one->count()); + EXPECT_EQ(answers1, posit); + + app.reset(); + + args = {"--", "--one", "two", "three"}; + std::vector<std::string> answers2 = {"--one", "two", "three"}; + run(); + + EXPECT_FALSE(one->count()); + EXPECT_EQ(answers2, posit); +} + +TEST_F(TApp, MixedPositionals) { + + int positional_int; + std::string positional_string; + app.add_option("posit1,--posit1", positional_int, ""); + app.add_option("posit2,--posit2", positional_string, ""); + + args = {"--posit2", "thing2", "7"}; + + run(); + + EXPECT_EQ((size_t)1, app.count("posit2")); + EXPECT_EQ((size_t)1, app.count("--posit1")); + EXPECT_EQ(7, positional_int); + EXPECT_EQ("thing2", positional_string); +} + +TEST_F(TApp, BigPositional) { + std::vector<std::string> vec; + app.add_option("pos", vec); + + args = {"one"}; + + run(); + EXPECT_EQ(args, vec); + + app.reset(); + + args = {"one", "two"}; + run(); + + EXPECT_EQ(args, vec); +} + +TEST_F(TApp, Reset) { + + app.add_flag("--simple"); + double doub; + app.add_option("-d,--double", doub); + + args = {"--simple", "--double", "1.2"}; + + run(); + + EXPECT_EQ((size_t)1, app.count("--simple")); + EXPECT_EQ((size_t)1, app.count("-d")); + EXPECT_DOUBLE_EQ(1.2, doub); + + app.reset(); + + EXPECT_EQ((size_t)0, app.count("--simple")); + EXPECT_EQ((size_t)0, app.count("-d")); + + run(); + + EXPECT_EQ((size_t)1, app.count("--simple")); + EXPECT_EQ((size_t)1, app.count("-d")); + EXPECT_DOUBLE_EQ(1.2, doub); +} + +TEST_F(TApp, RemoveOption) { + app.add_flag("--one"); + auto opt = app.add_flag("--two"); + + EXPECT_TRUE(app.remove_option(opt)); + EXPECT_FALSE(app.remove_option(opt)); + + args = {"--two"}; + + EXPECT_THROW(run(), CLI::ExtrasError); +} + +TEST_F(TApp, FileNotExists) { + std::string myfile{"TestNonFileNotUsed.txt"}; + EXPECT_NO_THROW(CLI::NonexistentPath(myfile)); + + std::string filename; + app.add_option("--file", filename)->check(CLI::NonexistentPath); + args = {"--file", myfile}; + + run(); + EXPECT_EQ(myfile, filename); + + app.reset(); + + bool ok = static_cast<bool>(std::ofstream(myfile.c_str()).put('a')); // create file + EXPECT_TRUE(ok); + EXPECT_THROW(run(), CLI::ValidationError); + + std::remove(myfile.c_str()); + EXPECT_FALSE(CLI::ExistingFile(myfile).empty()); +} + +TEST_F(TApp, FileExists) { + std::string myfile{"TestNonFileNotUsed.txt"}; + EXPECT_FALSE(CLI::ExistingFile(myfile).empty()); + + std::string filename = "Failed"; + app.add_option("--file", filename)->check(CLI::ExistingFile); + args = {"--file", myfile}; + + EXPECT_THROW(run(), CLI::ValidationError); + + app.reset(); + + bool ok = static_cast<bool>(std::ofstream(myfile.c_str()).put('a')); // create file + EXPECT_TRUE(ok); + run(); + EXPECT_EQ(myfile, filename); + + std::remove(myfile.c_str()); + EXPECT_FALSE(CLI::ExistingFile(myfile).empty()); +} + +TEST_F(TApp, InSet) { + + std::string choice; + app.add_set("-q,--quick", choice, {"one", "two", "three"}); + + args = {"--quick", "two"}; + + run(); + EXPECT_EQ("two", choice); + + app.reset(); + + args = {"--quick", "four"}; + EXPECT_THROW(run(), CLI::ConversionError); +} + +TEST_F(TApp, InSetWithDefault) { + + std::string choice = "one"; + app.add_set("-q,--quick", choice, {"one", "two", "three"}, "", true); + + run(); + EXPECT_EQ("one", choice); + app.reset(); + + args = {"--quick", "two"}; + + run(); + EXPECT_EQ("two", choice); + + app.reset(); + + args = {"--quick", "four"}; + EXPECT_THROW(run(), CLI::ConversionError); +} + +TEST_F(TApp, InCaselessSetWithDefault) { + + std::string choice = "one"; + app.add_set_ignore_case("-q,--quick", choice, {"one", "two", "three"}, "", true); + + run(); + EXPECT_EQ("one", choice); + app.reset(); + + args = {"--quick", "tWo"}; + + run(); + EXPECT_EQ("two", choice); + + app.reset(); + + args = {"--quick", "four"}; + EXPECT_THROW(run(), CLI::ConversionError); +} + +TEST_F(TApp, InIntSet) { + + int choice; + app.add_set("-q,--quick", choice, {1, 2, 3}); + + args = {"--quick", "2"}; + + run(); + EXPECT_EQ(2, choice); + + app.reset(); + + args = {"--quick", "4"}; + EXPECT_THROW(run(), CLI::ConversionError); +} + +TEST_F(TApp, FailSet) { + + int choice; + app.add_set("-q,--quick", choice, {1, 2, 3}); + + args = {"--quick", "3", "--quick=2"}; + EXPECT_THROW(run(), CLI::ArgumentMismatch); + + app.reset(); + + args = {"--quick=hello"}; + EXPECT_THROW(run(), CLI::ConversionError); +} + +TEST_F(TApp, InSetIgnoreCase) { + + std::string choice; + app.add_set_ignore_case("-q,--quick", choice, {"one", "Two", "THREE"}); + + args = {"--quick", "One"}; + run(); + EXPECT_EQ("one", choice); + + app.reset(); + args = {"--quick", "two"}; + run(); + EXPECT_EQ("Two", choice); // Keeps caps from set + + app.reset(); + args = {"--quick", "ThrEE"}; + run(); + EXPECT_EQ("THREE", choice); // Keeps caps from set + + app.reset(); + args = {"--quick", "four"}; + EXPECT_THROW(run(), CLI::ConversionError); + + app.reset(); + args = {"--quick=one", "--quick=two"}; + EXPECT_THROW(run(), CLI::ArgumentMismatch); +} + +TEST_F(TApp, VectorFixedString) { + std::vector<std::string> strvec; + std::vector<std::string> answer{"mystring", "mystring2", "mystring3"}; + + CLI::Option *opt = app.add_option("-s,--string", strvec)->expected(3); + EXPECT_EQ(3, opt->get_expected()); + + args = {"--string", "mystring", "mystring2", "mystring3"}; + run(); + EXPECT_EQ((size_t)3, app.count("--string")); + EXPECT_EQ(answer, strvec); +} + +TEST_F(TApp, VectorDefaultedFixedString) { + std::vector<std::string> strvec{"one"}; + std::vector<std::string> answer{"mystring", "mystring2", "mystring3"}; + + CLI::Option *opt = app.add_option("-s,--string", strvec, "", true)->expected(3); + EXPECT_EQ(3, opt->get_expected()); + + args = {"--string", "mystring", "mystring2", "mystring3"}; + run(); + EXPECT_EQ((size_t)3, app.count("--string")); + EXPECT_EQ(answer, strvec); +} + +TEST_F(TApp, VectorUnlimString) { + std::vector<std::string> strvec; + std::vector<std::string> answer{"mystring", "mystring2", "mystring3"}; + + CLI::Option *opt = app.add_option("-s,--string", strvec); + EXPECT_EQ(-1, opt->get_expected()); + + args = {"--string", "mystring", "mystring2", "mystring3"}; + run(); + EXPECT_EQ((size_t)3, app.count("--string")); + EXPECT_EQ(answer, strvec); + + app.reset(); + args = {"-s", "mystring", "mystring2", "mystring3"}; + run(); + EXPECT_EQ((size_t)3, app.count("--string")); + EXPECT_EQ(answer, strvec); +} + +TEST_F(TApp, VectorFancyOpts) { + std::vector<std::string> strvec; + std::vector<std::string> answer{"mystring", "mystring2", "mystring3"}; + + CLI::Option *opt = app.add_option("-s,--string", strvec)->required()->expected(3); + EXPECT_EQ(3, opt->get_expected()); + + args = {"--string", "mystring", "mystring2", "mystring3"}; + run(); + EXPECT_EQ((size_t)3, app.count("--string")); + EXPECT_EQ(answer, strvec); + + app.reset(); + args = {"one", "two"}; + EXPECT_THROW(run(), CLI::RequiredError); + + app.reset(); + EXPECT_THROW(run(), CLI::ParseError); +} + +TEST_F(TApp, OriginalOrder) { + std::vector<int> st1; + CLI::Option *op1 = app.add_option("-a", st1); + std::vector<int> st2; + CLI::Option *op2 = app.add_option("-b", st2); + + args = {"-a", "1", "-b", "2", "-a3", "-a", "4"}; + + run(); + + EXPECT_EQ(st1, std::vector<int>({1, 3, 4})); + EXPECT_EQ(st2, std::vector<int>({2})); + + EXPECT_EQ(app.parse_order(), std::vector<CLI::Option *>({op1, op2, op1, op1})); +} + +TEST_F(TApp, NeedsFlags) { + CLI::Option *opt = app.add_flag("-s,--string"); + app.add_flag("--both")->needs(opt); + + run(); + + app.reset(); + args = {"-s"}; + run(); + + app.reset(); + args = {"-s", "--both"}; + run(); + + app.reset(); + args = {"--both"}; + EXPECT_THROW(run(), CLI::RequiresError); +} + +TEST_F(TApp, ExcludesFlags) { + CLI::Option *opt = app.add_flag("-s,--string"); + app.add_flag("--nostr")->excludes(opt); + + run(); + + app.reset(); + args = {"-s"}; + run(); + + app.reset(); + args = {"--nostr"}; + run(); + + app.reset(); + args = {"--nostr", "-s"}; + EXPECT_THROW(run(), CLI::ExcludesError); + + app.reset(); + args = {"--string", "--nostr"}; + EXPECT_THROW(run(), CLI::ExcludesError); +} + +TEST_F(TApp, ExcludesMixedFlags) { + CLI::Option *opt1 = app.add_flag("--opt1"); + app.add_flag("--opt2"); + CLI::Option *opt3 = app.add_flag("--opt3"); + app.add_flag("--no")->excludes(opt1, "--opt2", opt3); + + run(); + + app.reset(); + args = {"--no"}; + run(); + + app.reset(); + args = {"--opt2"}; + run(); + + app.reset(); + args = {"--no", "--opt1"}; + EXPECT_THROW(run(), CLI::ExcludesError); + + app.reset(); + args = {"--no", "--opt2"}; + EXPECT_THROW(run(), CLI::ExcludesError); +} + +TEST_F(TApp, NeedsMultiFlags) { + CLI::Option *opt1 = app.add_flag("--opt1"); + CLI::Option *opt2 = app.add_flag("--opt2"); + CLI::Option *opt3 = app.add_flag("--opt3"); + app.add_flag("--optall")->needs(opt1, opt2, opt3); + + run(); + + app.reset(); + args = {"--opt1"}; + run(); + + app.reset(); + args = {"--opt2"}; + run(); + + app.reset(); + args = {"--optall"}; + EXPECT_THROW(run(), CLI::RequiresError); + + app.reset(); + args = {"--optall", "--opt1"}; + EXPECT_THROW(run(), CLI::RequiresError); + + app.reset(); + args = {"--optall", "--opt2", "--opt1"}; + EXPECT_THROW(run(), CLI::RequiresError); + + app.reset(); + args = {"--optall", "--opt1", "--opt2", "--opt3"}; + run(); +} + +TEST_F(TApp, NeedsMixedFlags) { + CLI::Option *opt1 = app.add_flag("--opt1"); + app.add_flag("--opt2"); + app.add_flag("--opt3"); + app.add_flag("--optall")->needs(opt1, "--opt2", "--opt3"); + + run(); + + app.reset(); + args = {"--opt1"}; + run(); + + app.reset(); + args = {"--opt2"}; + run(); + + app.reset(); + args = {"--optall"}; + EXPECT_THROW(run(), CLI::RequiresError); + + app.reset(); + args = {"--optall", "--opt1"}; + EXPECT_THROW(run(), CLI::RequiresError); + + app.reset(); + args = {"--optall", "--opt2", "--opt1"}; + EXPECT_THROW(run(), CLI::RequiresError); + + app.reset(); + args = {"--optall", "--opt1", "--opt2", "--opt3"}; + run(); +} + +#if __cplusplus <= 201703L + +TEST_F(TApp, RequiresMixedFlags) { + CLI::Option *opt1 = app.add_flag("--opt1"); + app.add_flag("--opt2"); + app.add_flag("--opt3"); + app.add_flag("--optall")->requires(opt1, "--opt2", "--opt3"); + + run(); + + app.reset(); + args = {"--opt1"}; + run(); + + app.reset(); + args = {"--opt2"}; + run(); + + app.reset(); + args = {"--optall"}; + EXPECT_THROW(run(), CLI::RequiresError); + + app.reset(); + args = {"--optall", "--opt1"}; + EXPECT_THROW(run(), CLI::RequiresError); + + app.reset(); + args = {"--optall", "--opt2", "--opt1"}; + EXPECT_THROW(run(), CLI::RequiresError); + + app.reset(); + args = {"--optall", "--opt1", "--opt2", "--opt3"}; + run(); +} + +#endif + +TEST_F(TApp, NeedsChainedFlags) { + CLI::Option *opt1 = app.add_flag("--opt1"); + CLI::Option *opt2 = app.add_flag("--opt2")->needs(opt1); + app.add_flag("--opt3")->needs(opt2); + + run(); + + app.reset(); + args = {"--opt1"}; + run(); + + app.reset(); + args = {"--opt2"}; + EXPECT_THROW(run(), CLI::RequiresError); + + app.reset(); + args = {"--opt3"}; + EXPECT_THROW(run(), CLI::RequiresError); + + app.reset(); + args = {"--opt3", "--opt2"}; + EXPECT_THROW(run(), CLI::RequiresError); + + app.reset(); + args = {"--opt3", "--opt1"}; + EXPECT_THROW(run(), CLI::RequiresError); + + app.reset(); + args = {"--opt2", "--opt1"}; + run(); + + app.reset(); + args = {"--opt1", "--opt2", "--opt3"}; + run(); +} + +TEST_F(TApp, Env) { + + put_env("CLI11_TEST_ENV_TMP", "2"); + + int val = 1; + CLI::Option *vopt = app.add_option("--tmp", val)->envname("CLI11_TEST_ENV_TMP"); + + run(); + + EXPECT_EQ(2, val); + EXPECT_EQ((size_t)1, vopt->count()); + + app.reset(); + vopt->required(); + run(); + + app.reset(); + unset_env("CLI11_TEST_ENV_TMP"); + EXPECT_THROW(run(), CLI::RequiredError); +} + +TEST_F(TApp, RangeInt) { + int x = 0; + app.add_option("--one", x)->check(CLI::Range(3, 6)); + + args = {"--one=1"}; + EXPECT_THROW(run(), CLI::ValidationError); + + app.reset(); + args = {"--one=7"}; + EXPECT_THROW(run(), CLI::ValidationError); + + app.reset(); + args = {"--one=3"}; + run(); + + app.reset(); + args = {"--one=5"}; + run(); + + app.reset(); + args = {"--one=6"}; + run(); +} + +TEST_F(TApp, RangeDouble) { + + double x = 0; + /// Note that this must be a double in Range, too + app.add_option("--one", x)->check(CLI::Range(3.0, 6.0)); + + args = {"--one=1"}; + EXPECT_THROW(run(), CLI::ValidationError); + + app.reset(); + args = {"--one=7"}; + EXPECT_THROW(run(), CLI::ValidationError); + + app.reset(); + args = {"--one=3"}; + run(); + + app.reset(); + args = {"--one=5"}; + run(); + + app.reset(); + args = {"--one=6"}; + run(); +} + +// Check to make sure progromatic access to left over is available +TEST_F(TApp, AllowExtras) { + + app.allow_extras(); + + bool val = true; + app.add_flag("-f", val); + EXPECT_FALSE(val); + + args = {"-x", "-f"}; + + EXPECT_NO_THROW(run()); + EXPECT_TRUE(val); + EXPECT_EQ(app.remaining(), std::vector<std::string>({"-x"})); +} + +TEST_F(TApp, AllowExtrasOrder) { + + app.allow_extras(); + + args = {"-x", "-f"}; + EXPECT_NO_THROW(run()); + EXPECT_EQ(app.remaining(), std::vector<std::string>({"-x", "-f"})); + app.reset(); + + std::vector<std::string> left_over = app.remaining(); + app.parse(left_over); + EXPECT_EQ(app.remaining(), left_over); +} + +// Test horrible error +TEST_F(TApp, CheckShortFail) { + args = {"--two"}; + + EXPECT_THROW(CLI::detail::AppFriend::parse_arg(&app, args, false), CLI::HorribleError); +} + +// Test horrible error +TEST_F(TApp, CheckLongFail) { + args = {"-t"}; + + EXPECT_THROW(CLI::detail::AppFriend::parse_arg(&app, args, true), CLI::HorribleError); +} + +// Test horrible error +TEST_F(TApp, CheckSubcomFail) { + args = {"subcom"}; + + EXPECT_THROW(CLI::detail::AppFriend::parse_subcommand(&app, args), CLI::HorribleError); +} + +TEST_F(TApp, OptionWithDefaults) { + int someint = 2; + app.add_option("-a", someint, "", true); + + args = {"-a1", "-a2"}; + + EXPECT_THROW(run(), CLI::ArgumentMismatch); +} + +TEST_F(TApp, SetWithDefaults) { + int someint = 2; + app.add_set("-a", someint, {1, 2, 3, 4}, "", true); + + args = {"-a1", "-a2"}; + + EXPECT_THROW(run(), CLI::ArgumentMismatch); +} + +TEST_F(TApp, SetWithDefaultsConversion) { + int someint = 2; + app.add_set("-a", someint, {1, 2, 3, 4}, "", true); + + args = {"-a", "hi"}; + + EXPECT_THROW(run(), CLI::ConversionError); +} + +TEST_F(TApp, SetWithDefaultsIC) { + std::string someint = "ho"; + app.add_set_ignore_case("-a", someint, {"Hi", "Ho"}, "", true); + + args = {"-aHi", "-aHo"}; + + EXPECT_THROW(run(), CLI::ArgumentMismatch); +} + +// Added to test ->transform +TEST_F(TApp, OrderedModifingTransforms) { + std::vector<std::string> val; + auto m = app.add_option("-m", val); + m->transform([](std::string x) { return x + "1"; }); + m->transform([](std::string x) { return x + "2"; }); + + args = {"-mone", "-mtwo"}; + + run(); + + EXPECT_EQ(val, std::vector<std::string>({"one12", "two12"})); +} + +TEST_F(TApp, ThrowingTransform) { + std::string val; + auto m = app.add_option("-m,--mess", val); + m->transform([](std::string) -> std::string { throw CLI::ValidationError("My Message"); }); + + EXPECT_NO_THROW(run()); + app.reset(); + + args = {"-mone"}; + + ASSERT_THROW(run(), CLI::ValidationError); + + app.reset(); + + try { + run(); + } catch(const CLI::ValidationError &e) { + EXPECT_EQ(e.what(), std::string("--mess: My Message")); + } +} diff --git a/packages/CLI11/tests/CMakeLists.txt b/packages/CLI11/tests/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..e2ae6d2c85e9c4badac2f8e2c85b5defd59b8f90 --- /dev/null +++ b/packages/CLI11/tests/CMakeLists.txt @@ -0,0 +1,54 @@ +set(GOOGLE_TEST_INDIVIDUAL ON) +include(AddGoogletest) + +set(CLI_TESTS + HelpersTest + IniTest + SimpleTest + AppTest + CreationTest + SubcommandTest + HelpTest + NewParseTest + ) + +set(CLI_MULTIONLY_TESTS + TimerTest + ) + +# Only affects current directory, so safe +include_directories(${CMAKE_CURRENT_SOURCE_DIR}) + +foreach(T ${CLI_TESTS}) + + add_executable(${T} ${T}.cpp ${CLI_headers}) + target_link_libraries(${T} PUBLIC CLI11) + add_gtest(${T}) + + if(CLI_SINGLE_FILE AND CLI_SINGLE_FILE_TESTS) + add_executable(${T}_Single ${T}.cpp) + target_link_libraries(${T}_Single PUBLIC CLI11_SINGLE) + add_gtest(${T}_Single) + set_target_properties(${T}_Single + PROPERTIES + FOLDER "Tests Single File") + endif() + +endforeach() + +foreach(T ${CLI_MULTIONLY_TESTS}) + + add_executable(${T} ${T}.cpp ${CLI_headers}) + target_link_libraries(${T} PUBLIC CLI11) + add_gtest(${T}) + +endforeach() + + +# Link test (build error if inlines missing) +add_library(link_test_1 link_test_1.cpp) +target_link_libraries(link_test_1 PUBLIC CLI11) +set_target_properties(link_test_1 PROPERTIES FOLDER "Tests") +add_executable(link_test_2 link_test_2.cpp) +target_link_libraries(link_test_2 PUBLIC CLI11 link_test_1) +add_gtest(link_test_2) diff --git a/packages/CLI11/tests/CreationTest.cpp b/packages/CLI11/tests/CreationTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b95e6c0a167706093c3216f02f0aa87d5683cdf3 --- /dev/null +++ b/packages/CLI11/tests/CreationTest.cpp @@ -0,0 +1,397 @@ +#include "app_helper.hpp" +#include <cstdlib> + +TEST_F(TApp, AddingExistingShort) { + app.add_flag("-c,--count"); + EXPECT_THROW(app.add_flag("--cat,-c"), CLI::OptionAlreadyAdded); +} + +TEST_F(TApp, AddingExistingLong) { + app.add_flag("-q,--count"); + EXPECT_THROW(app.add_flag("--count,-c"), CLI::OptionAlreadyAdded); +} + +TEST_F(TApp, AddingExistingShortNoCase) { + app.add_flag("-C,--count")->ignore_case(); + EXPECT_THROW(app.add_flag("--cat,-c"), CLI::OptionAlreadyAdded); +} + +TEST_F(TApp, AddingExistingLongNoCase) { + app.add_flag("-q,--count")->ignore_case(); + EXPECT_THROW(app.add_flag("--Count,-c"), CLI::OptionAlreadyAdded); +} + +TEST_F(TApp, AddingExistingNoCaseReversed) { + app.add_flag("-c,--count")->ignore_case(); + EXPECT_THROW(app.add_flag("--cat,-C"), CLI::OptionAlreadyAdded); +} + +TEST_F(TApp, AddingExistingWithCase) { + app.add_flag("-c,--count"); + EXPECT_NO_THROW(app.add_flag("--Cat,-C")); +} + +TEST_F(TApp, AddingExistingWithCaseAfter) { + auto count = app.add_flag("-c,--count"); + app.add_flag("--Cat,-C"); + + EXPECT_THROW(count->ignore_case(), CLI::OptionAlreadyAdded); +} + +TEST_F(TApp, AddingExistingWithCaseAfter2) { + app.add_flag("-c,--count"); + auto cat = app.add_flag("--Cat,-C"); + + EXPECT_THROW(cat->ignore_case(), CLI::OptionAlreadyAdded); +} + +TEST_F(TApp, AddingMultipleInfPositionals) { + std::vector<std::string> one, two; + app.add_option("one", one); + app.add_option("two", two); + + EXPECT_THROW(run(), CLI::InvalidError); +} + +TEST_F(TApp, AddingMultipleInfPositionalsSubcom) { + std::vector<std::string> one, two; + CLI::App *below = app.add_subcommand("below"); + below->add_option("one", one); + below->add_option("two", two); + + EXPECT_THROW(run(), CLI::InvalidError); +} + +TEST_F(TApp, MultipleSubcomMatching) { + app.add_subcommand("first"); + app.add_subcommand("second"); + app.add_subcommand("Second"); + EXPECT_THROW(app.add_subcommand("first"), CLI::OptionAlreadyAdded); +} + +TEST_F(TApp, RecoverSubcommands) { + CLI::App *app1 = app.add_subcommand("app1"); + CLI::App *app2 = app.add_subcommand("app2"); + CLI::App *app3 = app.add_subcommand("app3"); + CLI::App *app4 = app.add_subcommand("app4"); + + EXPECT_EQ(app.get_subcommands(false), std::vector<CLI::App *>({app1, app2, app3, app4})); +} + +TEST_F(TApp, MultipleSubcomMatchingWithCase) { + app.add_subcommand("first")->ignore_case(); + EXPECT_THROW(app.add_subcommand("fIrst"), CLI::OptionAlreadyAdded); +} + +TEST_F(TApp, MultipleSubcomMatchingWithCaseFirst) { + app.ignore_case(); + app.add_subcommand("first"); + EXPECT_THROW(app.add_subcommand("fIrst"), CLI::OptionAlreadyAdded); +} + +TEST_F(TApp, MultipleSubcomMatchingWithCaseInplace) { + app.add_subcommand("first"); + auto first = app.add_subcommand("fIrst"); + + EXPECT_THROW(first->ignore_case(), CLI::OptionAlreadyAdded); +} + +TEST_F(TApp, MultipleSubcomMatchingWithCaseInplace2) { + auto first = app.add_subcommand("first"); + app.add_subcommand("fIrst"); + + EXPECT_THROW(first->ignore_case(), CLI::OptionAlreadyAdded); +} + +TEST_F(TApp, MultipleSubcomNoMatchingInplace2) { + auto first = app.add_subcommand("first"); + auto second = app.add_subcommand("second"); + + EXPECT_NO_THROW(first->ignore_case()); + EXPECT_NO_THROW(second->ignore_case()); +} + +TEST_F(TApp, IncorrectConstructionFlagPositional1) { EXPECT_THROW(app.add_flag("cat"), CLI::IncorrectConstruction); } + +TEST_F(TApp, IncorrectConstructionFlagPositional2) { + int x; + EXPECT_THROW(app.add_flag("cat", x), CLI::IncorrectConstruction); +} + +TEST_F(TApp, IncorrectConstructionFlagPositional3) { + bool x; + EXPECT_THROW(app.add_flag("cat", x), CLI::IncorrectConstruction); +} + +TEST_F(TApp, IncorrectConstructionFlagExpected) { + auto cat = app.add_flag("--cat"); + EXPECT_NO_THROW(cat->expected(0)); + EXPECT_THROW(cat->expected(1), CLI::IncorrectConstruction); +} + +TEST_F(TApp, IncorrectConstructionOptionAsFlag) { + int x; + auto cat = app.add_option("--cat", x); + EXPECT_NO_THROW(cat->expected(1)); + EXPECT_THROW(cat->expected(0), CLI::IncorrectConstruction); + EXPECT_THROW(cat->expected(2), CLI::IncorrectConstruction); +} + +TEST_F(TApp, IncorrectConstructionOptionAsVector) { + int x; + auto cat = app.add_option("--cat", x); + EXPECT_THROW(cat->expected(2), CLI::IncorrectConstruction); +} + +TEST_F(TApp, IncorrectConstructionVectorAsFlag) { + std::vector<int> x; + auto cat = app.add_option("--cat", x); + EXPECT_THROW(cat->expected(0), CLI::IncorrectConstruction); +} + +TEST_F(TApp, IncorrectConstructionVectorTakeLast) { + std::vector<int> vec; + auto cat = app.add_option("--vec", vec); + EXPECT_THROW(cat->multi_option_policy(CLI::MultiOptionPolicy::TakeLast), CLI::IncorrectConstruction); +} + +TEST_F(TApp, IncorrectConstructionTakeLastExpected) { + std::vector<int> vec; + auto cat = app.add_option("--vec", vec); + cat->expected(1); + ASSERT_NO_THROW(cat->multi_option_policy(CLI::MultiOptionPolicy::TakeLast)); + EXPECT_THROW(cat->expected(2), CLI::IncorrectConstruction); +} + +TEST_F(TApp, IncorrectConstructionNeedsCannotFind) { + auto cat = app.add_flag("--cat"); + EXPECT_THROW(cat->needs("--nothing"), CLI::IncorrectConstruction); +} + +TEST_F(TApp, IncorrectConstructionExcludesCannotFind) { + auto cat = app.add_flag("--cat"); + EXPECT_THROW(cat->excludes("--nothing"), CLI::IncorrectConstruction); +} + +TEST_F(TApp, IncorrectConstructionDuplicateNeeds) { + auto cat = app.add_flag("--cat"); + auto other = app.add_flag("--other"); + ASSERT_NO_THROW(cat->needs(other)); + EXPECT_THROW(cat->needs(other), CLI::OptionAlreadyAdded); +} + +TEST_F(TApp, IncorrectConstructionDuplicateNeedsTxt) { + auto cat = app.add_flag("--cat"); + app.add_flag("--other"); + ASSERT_NO_THROW(cat->needs("--other")); + EXPECT_THROW(cat->needs("--other"), CLI::OptionAlreadyAdded); +} + +TEST_F(TApp, IncorrectConstructionDuplicateExcludes) { + auto cat = app.add_flag("--cat"); + auto other = app.add_flag("--other"); + ASSERT_NO_THROW(cat->excludes(other)); + EXPECT_THROW(cat->excludes(other), CLI::OptionAlreadyAdded); +} + +TEST_F(TApp, IncorrectConstructionDuplicateExcludesTxt) { + auto cat = app.add_flag("--cat"); + app.add_flag("--other"); + ASSERT_NO_THROW(cat->excludes("--other")); + EXPECT_THROW(cat->excludes("--other"), CLI::OptionAlreadyAdded); +} + +TEST_F(TApp, CheckName) { + auto long1 = app.add_flag("--long1"); + auto long2 = app.add_flag("--Long2"); + auto short1 = app.add_flag("-a"); + auto short2 = app.add_flag("-B"); + int x, y; + auto pos1 = app.add_option("pos1", x); + auto pos2 = app.add_option("pOs2", y); + + EXPECT_TRUE(long1->check_name("--long1")); + EXPECT_FALSE(long1->check_name("--lonG1")); + + EXPECT_TRUE(long2->check_name("--Long2")); + EXPECT_FALSE(long2->check_name("--long2")); + + EXPECT_TRUE(short1->check_name("-a")); + EXPECT_FALSE(short1->check_name("-A")); + + EXPECT_TRUE(short2->check_name("-B")); + EXPECT_FALSE(short2->check_name("-b")); + + EXPECT_TRUE(pos1->check_name("pos1")); + EXPECT_FALSE(pos1->check_name("poS1")); + + EXPECT_TRUE(pos2->check_name("pOs2")); + EXPECT_FALSE(pos2->check_name("pos2")); +} + +TEST_F(TApp, CheckNameNoCase) { + auto long1 = app.add_flag("--long1")->ignore_case(); + auto long2 = app.add_flag("--Long2")->ignore_case(); + auto short1 = app.add_flag("-a")->ignore_case(); + auto short2 = app.add_flag("-B")->ignore_case(); + int x, y; + auto pos1 = app.add_option("pos1", x)->ignore_case(); + auto pos2 = app.add_option("pOs2", y)->ignore_case(); + + EXPECT_TRUE(long1->check_name("--long1")); + EXPECT_TRUE(long1->check_name("--lonG1")); + + EXPECT_TRUE(long2->check_name("--Long2")); + EXPECT_TRUE(long2->check_name("--long2")); + + EXPECT_TRUE(short1->check_name("-a")); + EXPECT_TRUE(short1->check_name("-A")); + + EXPECT_TRUE(short2->check_name("-B")); + EXPECT_TRUE(short2->check_name("-b")); + + EXPECT_TRUE(pos1->check_name("pos1")); + EXPECT_TRUE(pos1->check_name("poS1")); + + EXPECT_TRUE(pos2->check_name("pOs2")); + EXPECT_TRUE(pos2->check_name("pos2")); +} + +TEST_F(TApp, PreSpaces) { + int x; + auto myapp = app.add_option(" -a, --long, other", x); + + EXPECT_TRUE(myapp->check_lname("long")); + EXPECT_TRUE(myapp->check_sname("a")); + EXPECT_TRUE(myapp->check_name("other")); +} + +TEST_F(TApp, AllSpaces) { + int x; + auto myapp = app.add_option(" -a , --long , other ", x); + + EXPECT_TRUE(myapp->check_lname("long")); + EXPECT_TRUE(myapp->check_sname("a")); + EXPECT_TRUE(myapp->check_name("other")); +} + +TEST_F(TApp, OptionFromDefaults) { + app.option_defaults()->required(); + + // Options should remember defaults + int x; + auto opt = app.add_option("--simple", x); + EXPECT_TRUE(opt->get_required()); + + // Flags cannot be required + auto flag = app.add_flag("--other"); + EXPECT_FALSE(flag->get_required()); + + app.option_defaults()->required(false); + auto opt2 = app.add_option("--simple2", x); + EXPECT_FALSE(opt2->get_required()); + + app.option_defaults()->required()->ignore_case(); + + auto opt3 = app.add_option("--simple3", x); + EXPECT_TRUE(opt3->get_required()); + EXPECT_TRUE(opt3->get_ignore_case()); +} + +TEST_F(TApp, OptionFromDefaultsSubcommands) { + // Initial defaults + EXPECT_FALSE(app.option_defaults()->get_required()); + EXPECT_EQ(app.option_defaults()->get_multi_option_policy(), CLI::MultiOptionPolicy::Throw); + EXPECT_FALSE(app.option_defaults()->get_ignore_case()); + EXPECT_TRUE(app.option_defaults()->get_configurable()); + EXPECT_EQ(app.option_defaults()->get_group(), "Options"); + + app.option_defaults() + ->required() + ->multi_option_policy(CLI::MultiOptionPolicy::TakeLast) + ->ignore_case() + ->configurable(false) + ->group("Something"); + + auto app2 = app.add_subcommand("app2"); + + EXPECT_TRUE(app2->option_defaults()->get_required()); + EXPECT_EQ(app2->option_defaults()->get_multi_option_policy(), CLI::MultiOptionPolicy::TakeLast); + EXPECT_TRUE(app2->option_defaults()->get_ignore_case()); + EXPECT_FALSE(app2->option_defaults()->get_configurable()); + EXPECT_EQ(app2->option_defaults()->get_group(), "Something"); +} + +TEST_F(TApp, HelpFlagFromDefaultsSubcommands) { + app.set_help_flag("--that", "Wow"); + + auto app2 = app.add_subcommand("app2"); + + EXPECT_EQ(app2->get_help_ptr()->get_name(), "--that"); + EXPECT_EQ(app2->get_help_ptr()->get_description(), "Wow"); +} + +TEST_F(TApp, SubcommandDefaults) { + // allow_extras, prefix_command, ignore_case, fallthrough, group, min/max subcommand + + // Initial defaults + EXPECT_FALSE(app.get_allow_extras()); + EXPECT_FALSE(app.get_prefix_command()); + EXPECT_FALSE(app.get_ignore_case()); + EXPECT_FALSE(app.get_fallthrough()); + EXPECT_EQ(app.get_footer(), ""); + EXPECT_EQ(app.get_group(), "Subcommands"); + EXPECT_EQ(app.get_require_subcommand_min(), (size_t)0); + EXPECT_EQ(app.get_require_subcommand_max(), (size_t)0); + + app.allow_extras(); + app.prefix_command(); + app.ignore_case(); + app.fallthrough(); + app.set_footer("footy"); + app.group("Stuff"); + app.require_subcommand(2, 3); + + auto app2 = app.add_subcommand("app2"); + + // Initial defaults + EXPECT_TRUE(app2->get_allow_extras()); + EXPECT_TRUE(app2->get_prefix_command()); + EXPECT_TRUE(app2->get_ignore_case()); + EXPECT_TRUE(app2->get_fallthrough()); + EXPECT_EQ(app2->get_footer(), "footy"); + EXPECT_EQ(app2->get_group(), "Stuff"); + EXPECT_EQ(app2->get_require_subcommand_min(), (size_t)0); + EXPECT_EQ(app2->get_require_subcommand_max(), (size_t)3); +} + +TEST_F(TApp, SubcommandMinMax) { + + EXPECT_EQ(app.get_require_subcommand_min(), (size_t)0); + EXPECT_EQ(app.get_require_subcommand_max(), (size_t)0); + + app.require_subcommand(); + + EXPECT_EQ(app.get_require_subcommand_min(), (size_t)1); + EXPECT_EQ(app.get_require_subcommand_max(), (size_t)0); + + app.require_subcommand(2); + + EXPECT_EQ(app.get_require_subcommand_min(), (size_t)2); + EXPECT_EQ(app.get_require_subcommand_max(), (size_t)2); + + app.require_subcommand(0); + + EXPECT_EQ(app.get_require_subcommand_min(), (size_t)0); + EXPECT_EQ(app.get_require_subcommand_max(), (size_t)0); + + app.require_subcommand(-2); + + EXPECT_EQ(app.get_require_subcommand_min(), (size_t)0); + EXPECT_EQ(app.get_require_subcommand_max(), (size_t)2); + + app.require_subcommand(3, 7); + + EXPECT_EQ(app.get_require_subcommand_min(), (size_t)3); + EXPECT_EQ(app.get_require_subcommand_max(), (size_t)7); +} diff --git a/packages/CLI11/tests/HelpTest.cpp b/packages/CLI11/tests/HelpTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..60092d2d35c0c20b757d1d9158e7ec5974a7ab4c --- /dev/null +++ b/packages/CLI11/tests/HelpTest.cpp @@ -0,0 +1,452 @@ +#ifdef CLI_SINGLE_FILE +#include "CLI11.hpp" +#else +#include "CLI/CLI.hpp" +#endif + +#include "gtest/gtest.h" +#include "gmock/gmock.h" +#include <fstream> + +using ::testing::HasSubstr; +using ::testing::Not; + +TEST(THelp, Basic) { + CLI::App app{"My prog"}; + + std::string help = app.help(); + + EXPECT_THAT(help, HasSubstr("My prog")); + EXPECT_THAT(help, HasSubstr("-h,--help")); + EXPECT_THAT(help, HasSubstr("Options:")); + EXPECT_THAT(help, HasSubstr("Usage:")); +} + +TEST(THelp, Footer) { + CLI::App app{"My prog"}; + app.set_footer("Report bugs to bugs@example.com"); + + std::string help = app.help(); + + EXPECT_THAT(help, HasSubstr("My prog")); + EXPECT_THAT(help, HasSubstr("-h,--help")); + EXPECT_THAT(help, HasSubstr("Options:")); + EXPECT_THAT(help, HasSubstr("Usage:")); + EXPECT_THAT(help, HasSubstr("Report bugs to bugs@example.com")); +} + +TEST(THelp, OptionalPositional) { + CLI::App app{"My prog"}; + + std::string x; + app.add_option("something", x, "My option here"); + + std::string help = app.help(); + + EXPECT_THAT(help, HasSubstr("My prog")); + EXPECT_THAT(help, HasSubstr("-h,--help")); + EXPECT_THAT(help, HasSubstr("Options:")); + EXPECT_THAT(help, HasSubstr("Positionals:")); + EXPECT_THAT(help, HasSubstr("something TEXT")); + EXPECT_THAT(help, HasSubstr("My option here")); + EXPECT_THAT(help, HasSubstr("Usage: program [OPTIONS] [something]")); +} + +TEST(THelp, Hidden) { + CLI::App app{"My prog"}; + + std::string x; + app.add_option("something", x, "My option here")->group(""); + std::string y; + app.add_option("--another", y)->group(""); + + std::string help = app.help(); + + EXPECT_THAT(help, HasSubstr("My prog")); + EXPECT_THAT(help, HasSubstr("-h,--help")); + EXPECT_THAT(help, HasSubstr("Options:")); + EXPECT_THAT(help, HasSubstr("[something]")); + EXPECT_THAT(help, Not(HasSubstr("something "))); + EXPECT_THAT(help, Not(HasSubstr("another"))); +} + +TEST(THelp, OptionalPositionalAndOptions) { + CLI::App app{"My prog"}; + app.add_flag("-q,--quick"); + + std::string x; + app.add_option("something", x, "My option here"); + + std::string help = app.help(); + + EXPECT_THAT(help, HasSubstr("My prog")); + EXPECT_THAT(help, HasSubstr("-h,--help")); + EXPECT_THAT(help, HasSubstr("Options:")); + EXPECT_THAT(help, HasSubstr("Usage: program [OPTIONS] [something]")); +} + +TEST(THelp, RequiredPositionalAndOptions) { + CLI::App app{"My prog"}; + app.add_flag("-q,--quick"); + + std::string x; + app.add_option("something", x, "My option here")->required(); + + std::string help = app.help(); + + EXPECT_THAT(help, HasSubstr("My prog")); + EXPECT_THAT(help, HasSubstr("-h,--help")); + EXPECT_THAT(help, HasSubstr("Options:")); + EXPECT_THAT(help, HasSubstr("Positionals:")); + EXPECT_THAT(help, HasSubstr("Usage: program [OPTIONS] something")); +} + +TEST(THelp, MultiOpts) { + CLI::App app{"My prog"}; + std::vector<int> x, y; + app.add_option("-q,--quick", x, "Disc")->expected(2); + app.add_option("-v,--vals", y, "Other"); + + std::string help = app.help(); + + EXPECT_THAT(help, HasSubstr("My prog")); + EXPECT_THAT(help, Not(HasSubstr("Positionals:"))); + EXPECT_THAT(help, HasSubstr("Usage: program [OPTIONS]")); + EXPECT_THAT(help, HasSubstr("INT x 2")); + EXPECT_THAT(help, HasSubstr("INT ...")); +} + +TEST(THelp, VectorOpts) { + CLI::App app{"My prog"}; + std::vector<int> x = {1, 2}; + app.add_option("-q,--quick", x, "", true); + + std::string help = app.help(); + + EXPECT_THAT(help, HasSubstr("INT=[1,2] ...")); +} + +TEST(THelp, MultiPosOpts) { + CLI::App app{"My prog"}; + std::vector<int> x, y; + app.add_option("quick", x, "Disc")->expected(2); + app.add_option("vals", y, "Other"); + + std::string help = app.help(); + + EXPECT_THAT(help, HasSubstr("My prog")); + EXPECT_THAT(help, HasSubstr("Positionals:")); + EXPECT_THAT(help, HasSubstr("Usage: program [OPTIONS]")); + EXPECT_THAT(help, HasSubstr("INT x 2")); + EXPECT_THAT(help, HasSubstr("INT ...")); + EXPECT_THAT(help, HasSubstr("[quick(2x)]")); + EXPECT_THAT(help, HasSubstr("[vals...]")); +} + +TEST(THelp, EnvName) { + CLI::App app{"My prog"}; + std::string input; + app.add_option("--something", input)->envname("SOME_ENV"); + + std::string help = app.help(); + + EXPECT_THAT(help, HasSubstr("SOME_ENV")); +} + +TEST(THelp, Needs) { + CLI::App app{"My prog"}; + + CLI::Option *op1 = app.add_flag("--op1"); + app.add_flag("--op2")->needs(op1); + + std::string help = app.help(); + + EXPECT_THAT(help, HasSubstr("Requires: --op1")); +} + +TEST(THelp, NeedsPositional) { + CLI::App app{"My prog"}; + + int x, y; + + CLI::Option *op1 = app.add_option("op1", x, "one"); + app.add_option("op2", y, "two")->needs(op1); + + std::string help = app.help(); + + EXPECT_THAT(help, HasSubstr("Positionals:")); + EXPECT_THAT(help, HasSubstr("Requires: op1")); +} + +TEST(THelp, Excludes) { + CLI::App app{"My prog"}; + + CLI::Option *op1 = app.add_flag("--op1"); + app.add_flag("--op2")->excludes(op1); + + std::string help = app.help(); + + EXPECT_THAT(help, HasSubstr("Excludes: --op1")); +} + +TEST(THelp, ExcludesPositional) { + CLI::App app{"My prog"}; + + int x, y; + + CLI::Option *op1 = app.add_option("op1", x); + app.add_option("op2", y)->excludes(op1); + + std::string help = app.help(); + + EXPECT_THAT(help, HasSubstr("Positionals:")); + EXPECT_THAT(help, HasSubstr("Excludes: op1")); +} + +TEST(THelp, ManualSetters) { + + CLI::App app{"My prog"}; + + int x = 1; + + CLI::Option *op1 = app.add_option("--op", x); + op1->set_default_str("12"); + op1->set_type_name("BIGGLES"); + EXPECT_EQ(x, 1); + + std::string help = app.help(); + + EXPECT_THAT(help, HasSubstr("=12")); + EXPECT_THAT(help, HasSubstr("BIGGLES")); + + op1->set_default_val("14"); + EXPECT_EQ(x, 14); + help = app.help(); + EXPECT_THAT(help, HasSubstr("=14")); +} + +TEST(THelp, Subcom) { + CLI::App app{"My prog"}; + + auto sub1 = app.add_subcommand("sub1"); + app.add_subcommand("sub2"); + + std::string help = app.help(); + EXPECT_THAT(help, HasSubstr("Usage: program [OPTIONS] [SUBCOMMAND]")); + + app.require_subcommand(); + + help = app.help(); + EXPECT_THAT(help, HasSubstr("Usage: program [OPTIONS] SUBCOMMAND")); + + help = sub1->help(); + EXPECT_THAT(help, HasSubstr("Usage: sub1")); + + char x[] = "./myprogram"; + char y[] = "sub2"; + + std::vector<char *> args = {x, y}; + app.parse((int)args.size(), args.data()); + + help = app.help(); + EXPECT_THAT(help, HasSubstr("Usage: ./myprogram sub2")); +} + +TEST(THelp, IntDefaults) { + CLI::App app{"My prog"}; + + int one{1}, two{2}; + app.add_option("--one", one, "Help for one", true); + app.add_set("--set", two, {2, 3, 4}, "Help for set", true); + + std::string help = app.help(); + + EXPECT_THAT(help, HasSubstr("--one")); + EXPECT_THAT(help, HasSubstr("--set")); + EXPECT_THAT(help, HasSubstr("1")); + EXPECT_THAT(help, HasSubstr("=2")); + EXPECT_THAT(help, HasSubstr("2,3,4")); +} + +TEST(THelp, SetLower) { + CLI::App app{"My prog"}; + + std::string def{"One"}; + app.add_set_ignore_case("--set", def, {"oNe", "twO", "THREE"}, "Help for set", true); + + std::string help = app.help(); + + EXPECT_THAT(help, HasSubstr("--set")); + EXPECT_THAT(help, HasSubstr("=One")); + EXPECT_THAT(help, HasSubstr("oNe")); + EXPECT_THAT(help, HasSubstr("twO")); + EXPECT_THAT(help, HasSubstr("THREE")); +} + +TEST(THelp, OnlyOneHelp) { + CLI::App app{"My prog"}; + + // It is not supported to have more than one help flag, last one wins + app.set_help_flag("--help", "No short name allowed"); + app.set_help_flag("--yelp", "Alias for help"); + + std::vector<std::string> input{"--help"}; + EXPECT_THROW(app.parse(input), CLI::ExtrasError); +} + +TEST(THelp, RemoveHelp) { + CLI::App app{"My prog"}; + app.set_help_flag(); + + std::string help = app.help(); + + EXPECT_THAT(help, HasSubstr("My prog")); + EXPECT_THAT(help, Not(HasSubstr("-h,--help"))); + EXPECT_THAT(help, Not(HasSubstr("Options:"))); + EXPECT_THAT(help, HasSubstr("Usage:")); + + std::vector<std::string> input{"--help"}; + try { + app.parse(input); + } catch(const CLI::ParseError &e) { + EXPECT_EQ(static_cast<int>(CLI::ExitCodes::ExtrasError), e.get_exit_code()); + } +} + +TEST(THelp, NoHelp) { + CLI::App app{"My prog"}; + app.set_help_flag(); + + std::string help = app.help(); + + EXPECT_THAT(help, HasSubstr("My prog")); + EXPECT_THAT(help, Not(HasSubstr("-h,--help"))); + EXPECT_THAT(help, Not(HasSubstr("Options:"))); + EXPECT_THAT(help, HasSubstr("Usage:")); + + std::vector<std::string> input{"--help"}; + try { + app.parse(input); + } catch(const CLI::ParseError &e) { + EXPECT_EQ(static_cast<int>(CLI::ExitCodes::ExtrasError), e.get_exit_code()); + } +} + +TEST(THelp, CustomHelp) { + CLI::App app{"My prog"}; + + CLI::Option *help_option = app.set_help_flag("--yelp", "display help and exit"); + EXPECT_EQ(app.get_help_ptr(), help_option); + + std::string help = app.help(); + + EXPECT_THAT(help, HasSubstr("My prog")); + EXPECT_THAT(help, Not(HasSubstr("-h,--help"))); + EXPECT_THAT(help, HasSubstr("--yelp")); + EXPECT_THAT(help, HasSubstr("Options:")); + EXPECT_THAT(help, HasSubstr("Usage:")); + + std::vector<std::string> input{"--yelp"}; + try { + app.parse(input); + } catch(const CLI::CallForHelp &e) { + EXPECT_EQ(static_cast<int>(CLI::ExitCodes::Success), e.get_exit_code()); + } +} + +TEST(THelp, NiceName) { + CLI::App app; + + int x; + auto long_name = app.add_option("-s,--long,-q,--other,that", x); + auto short_name = app.add_option("more,-x,-y", x); + auto positional = app.add_option("posit", x); + + EXPECT_EQ(long_name->single_name(), "--long"); + EXPECT_EQ(short_name->single_name(), "-x"); + EXPECT_EQ(positional->single_name(), "posit"); +} + +TEST(Exit, ErrorWithHelp) { + CLI::App app{"My prog"}; + + std::vector<std::string> input{"-h"}; + try { + app.parse(input); + } catch(const CLI::CallForHelp &e) { + EXPECT_EQ(static_cast<int>(CLI::ExitCodes::Success), e.get_exit_code()); + } +} + +TEST(Exit, ErrorWithoutHelp) { + CLI::App app{"My prog"}; + + std::vector<std::string> input{"--none"}; + try { + app.parse(input); + } catch(const CLI::ParseError &e) { + EXPECT_EQ(static_cast<int>(CLI::ExitCodes::ExtrasError), e.get_exit_code()); + } +} + +TEST(Exit, ExitCodes) { + CLI::App app; + + auto i = static_cast<int>(CLI::ExitCodes::ExtrasError); + EXPECT_EQ(0, app.exit(CLI::Success())); + EXPECT_EQ(0, app.exit(CLI::CallForHelp())); + EXPECT_EQ(i, app.exit(CLI::ExtrasError({"Thing"}))); + EXPECT_EQ(42, app.exit(CLI::RuntimeError(42))); + EXPECT_EQ(1, app.exit(CLI::RuntimeError())); // Not sure if a default here is a good thing +} + +struct CapturedHelp : public ::testing::Test { + CLI::App app{"My Test Program"}; + std::stringstream out; + std::stringstream err; + + int run(const CLI::Error &e) { return app.exit(e, out, err); } + + void reset() { + out.clear(); + err.clear(); + } +}; + +TEST_F(CapturedHelp, Sucessful) { + EXPECT_EQ(run(CLI::Success()), 0); + EXPECT_EQ(out.str(), ""); + EXPECT_EQ(err.str(), ""); +} + +TEST_F(CapturedHelp, JustAnError) { + EXPECT_EQ(run(CLI::RuntimeError(42)), 42); + EXPECT_EQ(out.str(), ""); + EXPECT_EQ(err.str(), ""); +} + +TEST_F(CapturedHelp, CallForHelp) { + EXPECT_EQ(run(CLI::CallForHelp()), 0); + EXPECT_EQ(out.str(), app.help()); + EXPECT_EQ(err.str(), ""); +} + +TEST_F(CapturedHelp, NormalError) { + EXPECT_EQ(run(CLI::ExtrasError({"Thing"})), static_cast<int>(CLI::ExitCodes::ExtrasError)); + EXPECT_EQ(out.str(), ""); + EXPECT_THAT(err.str(), HasSubstr("for more information")); + EXPECT_THAT(err.str(), Not(HasSubstr("ExtrasError"))); + EXPECT_THAT(err.str(), HasSubstr("Thing")); + EXPECT_THAT(err.str(), Not(HasSubstr("Usage"))); +} + +TEST_F(CapturedHelp, RepacedError) { + app.set_failure_message(CLI::FailureMessage::help); + + EXPECT_EQ(run(CLI::ExtrasError({"Thing"})), static_cast<int>(CLI::ExitCodes::ExtrasError)); + EXPECT_EQ(out.str(), ""); + EXPECT_THAT(err.str(), Not(HasSubstr("for more information"))); + EXPECT_THAT(err.str(), HasSubstr("ERROR: ExtrasError")); + EXPECT_THAT(err.str(), HasSubstr("Thing")); + EXPECT_THAT(err.str(), HasSubstr("Usage")); +} diff --git a/packages/CLI11/tests/HelpersTest.cpp b/packages/CLI11/tests/HelpersTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0f6d87a6090d2cea5eda013dc6e6f6bdeb5aa9e5 --- /dev/null +++ b/packages/CLI11/tests/HelpersTest.cpp @@ -0,0 +1,437 @@ +#include "app_helper.hpp" + +#include <cstdio> +#include <fstream> +#include <cstdint> +#include <string> +#include <complex> + +TEST(Split, SimpleByToken) { + auto out = CLI::detail::split("one.two.three", '.'); + ASSERT_EQ((size_t)3, out.size()); + EXPECT_EQ("one", out.at(0)); + EXPECT_EQ("two", out.at(1)); + EXPECT_EQ("three", out.at(2)); +} + +TEST(Split, Single) { + auto out = CLI::detail::split("one", '.'); + ASSERT_EQ((size_t)1, out.size()); + EXPECT_EQ("one", out.at(0)); +} + +TEST(Split, Empty) { + auto out = CLI::detail::split("", '.'); + ASSERT_EQ((size_t)1, out.size()); + EXPECT_EQ("", out.at(0)); +} + +TEST(String, InvalidName) { + EXPECT_TRUE(CLI::detail::valid_name_string("valid")); + EXPECT_FALSE(CLI::detail::valid_name_string("-invalid")); + EXPECT_TRUE(CLI::detail::valid_name_string("va-li-d")); + EXPECT_FALSE(CLI::detail::valid_name_string("vali&d")); + EXPECT_TRUE(CLI::detail::valid_name_string("_valid")); +} + +TEST(Trim, Various) { + std::string s1{" sdlfkj sdflk sd s "}; + std::string a1{"sdlfkj sdflk sd s"}; + CLI::detail::trim(s1); + EXPECT_EQ(a1, s1); + + std::string s2{" a \t"}; + CLI::detail::trim(s2); + EXPECT_EQ("a", s2); + + std::string s3{" a \n"}; + CLI::detail::trim(s3); + EXPECT_EQ("a", s3); + + std::string s4{" a b "}; + EXPECT_EQ("a b", CLI::detail::trim(s4)); +} + +TEST(Trim, VariousFilters) { + std::string s1{" sdlfkj sdflk sd s "}; + std::string a1{"sdlfkj sdflk sd s"}; + CLI::detail::trim(s1, " "); + EXPECT_EQ(a1, s1); + + std::string s2{" a \t"}; + CLI::detail::trim(s2, " "); + EXPECT_EQ("a \t", s2); + + std::string s3{"abdavda"}; + CLI::detail::trim(s3, "a"); + EXPECT_EQ("bdavd", s3); + + std::string s4{"abcabcabc"}; + EXPECT_EQ("cabcabc", CLI::detail::trim(s4, "ab")); +} + +TEST(Trim, TrimCopy) { + std::string orig{" cabc "}; + std::string trimmed = CLI::detail::trim_copy(orig); + EXPECT_EQ("cabc", trimmed); + EXPECT_NE(orig, trimmed); + CLI::detail::trim(orig); + EXPECT_EQ(trimmed, orig); + + orig = "abcabcabc"; + trimmed = CLI::detail::trim_copy(orig, "ab"); + EXPECT_EQ("cabcabc", trimmed); + EXPECT_NE(orig, trimmed); + CLI::detail::trim(orig, "ab"); + EXPECT_EQ(trimmed, orig); +} + +TEST(Validators, FileExists) { + std::string myfile{"TestFileNotUsed.txt"}; + EXPECT_FALSE(CLI::ExistingFile(myfile).empty()); + bool ok = static_cast<bool>(std::ofstream(myfile.c_str()).put('a')); // create file + EXPECT_TRUE(ok); + EXPECT_TRUE(CLI::ExistingFile(myfile).empty()); + + std::remove(myfile.c_str()); + EXPECT_FALSE(CLI::ExistingFile(myfile).empty()); +} + +TEST(Validators, FileNotExists) { + std::string myfile{"TestFileNotUsed.txt"}; + EXPECT_TRUE(CLI::NonexistentPath(myfile).empty()); + bool ok = static_cast<bool>(std::ofstream(myfile.c_str()).put('a')); // create file + EXPECT_TRUE(ok); + EXPECT_FALSE(CLI::NonexistentPath(myfile).empty()); + + std::remove(myfile.c_str()); + EXPECT_TRUE(CLI::NonexistentPath(myfile).empty()); +} + +TEST(Validators, FileIsDir) { + std::string mydir{"../tests"}; + EXPECT_NE(CLI::ExistingFile(mydir), ""); +} + +TEST(Validators, DirectoryExists) { + std::string mydir{"../tests"}; + EXPECT_EQ(CLI::ExistingDirectory(mydir), ""); +} + +TEST(Validators, DirectoryNotExists) { + std::string mydir{"nondirectory"}; + EXPECT_NE(CLI::ExistingDirectory(mydir), ""); +} + +TEST(Validators, DirectoryIsFile) { + std::string myfile{"TestFileNotUsed.txt"}; + EXPECT_TRUE(CLI::NonexistentPath(myfile).empty()); + bool ok = static_cast<bool>(std::ofstream(myfile.c_str()).put('a')); // create file + EXPECT_TRUE(ok); + EXPECT_FALSE(CLI::ExistingDirectory(myfile).empty()); + + std::remove(myfile.c_str()); + EXPECT_TRUE(CLI::NonexistentPath(myfile).empty()); +} + +TEST(Validators, PathExistsDir) { + std::string mydir{"../tests"}; + EXPECT_EQ(CLI::ExistingPath(mydir), ""); +} + +TEST(Validators, PathExistsFile) { + std::string myfile{"TestFileNotUsed.txt"}; + EXPECT_FALSE(CLI::ExistingPath(myfile).empty()); + bool ok = static_cast<bool>(std::ofstream(myfile.c_str()).put('a')); // create file + EXPECT_TRUE(ok); + EXPECT_TRUE(CLI::ExistingPath(myfile).empty()); + + std::remove(myfile.c_str()); + EXPECT_FALSE(CLI::ExistingPath(myfile).empty()); +} + +TEST(Validators, PathNotExistsDir) { + std::string mydir{"nonpath"}; + EXPECT_NE(CLI::ExistingPath(mydir), ""); +} + +// Yes, this is testing an app_helper :) +TEST(AppHelper, TempfileCreated) { + std::string name = "TestFileNotUsed.txt"; + { + TempFile myfile{name}; + + EXPECT_FALSE(CLI::ExistingFile(myfile).empty()); + + bool ok = static_cast<bool>(std::ofstream(myfile.c_str()).put('a')); // create file + EXPECT_TRUE(ok); + EXPECT_TRUE(CLI::ExistingFile(name).empty()); + EXPECT_THROW({ TempFile otherfile(name); }, std::runtime_error); + } + EXPECT_FALSE(CLI::ExistingFile(name).empty()); +} + +TEST(AppHelper, TempfileNotCreated) { + std::string name = "TestFileNotUsed.txt"; + { + TempFile myfile{name}; + + EXPECT_FALSE(CLI::ExistingFile(myfile).empty()); + } + EXPECT_FALSE(CLI::ExistingFile(name).empty()); +} + +TEST(AppHelper, Ofstream) { + + std::string name = "TestFileNotUsed.txt"; + { + TempFile myfile(name); + + { + std::ofstream out{myfile}; + out << "this is output" << std::endl; + } + + EXPECT_TRUE(CLI::ExistingFile(myfile).empty()); + } + EXPECT_FALSE(CLI::ExistingFile(name).empty()); +} + +TEST(Split, StringList) { + + std::vector<std::string> results{"a", "long", "--lone", "-q"}; + EXPECT_EQ(results, CLI::detail::split_names("a,long,--lone,-q")); + EXPECT_EQ(results, CLI::detail::split_names(" a, long, --lone, -q")); + EXPECT_EQ(results, CLI::detail::split_names(" a , long , --lone , -q ")); + EXPECT_EQ(results, CLI::detail::split_names(" a , long , --lone , -q ")); + + EXPECT_EQ(std::vector<std::string>({"one"}), CLI::detail::split_names("one")); +} + +TEST(RegEx, Shorts) { + std::string name, value; + + EXPECT_TRUE(CLI::detail::split_short("-a", name, value)); + EXPECT_EQ("a", name); + EXPECT_EQ("", value); + + EXPECT_TRUE(CLI::detail::split_short("-B", name, value)); + EXPECT_EQ("B", name); + EXPECT_EQ("", value); + + EXPECT_TRUE(CLI::detail::split_short("-cc", name, value)); + EXPECT_EQ("c", name); + EXPECT_EQ("c", value); + + EXPECT_TRUE(CLI::detail::split_short("-simple", name, value)); + EXPECT_EQ("s", name); + EXPECT_EQ("imple", value); + + EXPECT_FALSE(CLI::detail::split_short("--a", name, value)); + EXPECT_FALSE(CLI::detail::split_short("--thing", name, value)); + EXPECT_FALSE(CLI::detail::split_short("--", name, value)); + EXPECT_FALSE(CLI::detail::split_short("something", name, value)); + EXPECT_FALSE(CLI::detail::split_short("s", name, value)); +} + +TEST(RegEx, Longs) { + std::string name, value; + + EXPECT_TRUE(CLI::detail::split_long("--a", name, value)); + EXPECT_EQ("a", name); + EXPECT_EQ("", value); + + EXPECT_TRUE(CLI::detail::split_long("--thing", name, value)); + EXPECT_EQ("thing", name); + EXPECT_EQ("", value); + + EXPECT_TRUE(CLI::detail::split_long("--some=thing", name, value)); + EXPECT_EQ("some", name); + EXPECT_EQ("thing", value); + + EXPECT_FALSE(CLI::detail::split_long("-a", name, value)); + EXPECT_FALSE(CLI::detail::split_long("-things", name, value)); + EXPECT_FALSE(CLI::detail::split_long("Q", name, value)); + EXPECT_FALSE(CLI::detail::split_long("--", name, value)); +} + +TEST(RegEx, SplittingNew) { + + std::vector<std::string> shorts; + std::vector<std::string> longs; + std::string pname; + + EXPECT_NO_THROW(std::tie(shorts, longs, pname) = CLI::detail::get_names({"--long", "-s", "-q", "--also-long"})); + EXPECT_EQ(std::vector<std::string>({"long", "also-long"}), longs); + EXPECT_EQ(std::vector<std::string>({"s", "q"}), shorts); + EXPECT_EQ("", pname); + + EXPECT_NO_THROW(std::tie(shorts, longs, pname) = + CLI::detail::get_names({"--long", "", "-s", "-q", "", "--also-long"})); + EXPECT_EQ(std::vector<std::string>({"long", "also-long"}), longs); + EXPECT_EQ(std::vector<std::string>({"s", "q"}), shorts); + + EXPECT_THROW(std::tie(shorts, longs, pname) = CLI::detail::get_names({"-"}), CLI::BadNameString); + EXPECT_THROW(std::tie(shorts, longs, pname) = CLI::detail::get_names({"--"}), CLI::BadNameString); + EXPECT_THROW(std::tie(shorts, longs, pname) = CLI::detail::get_names({"-hi"}), CLI::BadNameString); + EXPECT_THROW(std::tie(shorts, longs, pname) = CLI::detail::get_names({"---hi"}), CLI::BadNameString); + EXPECT_THROW(std::tie(shorts, longs, pname) = CLI::detail::get_names({"one", "two"}), CLI::BadNameString); +} + +TEST(String, ToLower) { EXPECT_EQ("one and two", CLI::detail::to_lower("one And TWO")); } + +TEST(Join, Forward) { + std::vector<std::string> val{{"one", "two", "three"}}; + EXPECT_EQ("one,two,three", CLI::detail::join(val)); + EXPECT_EQ("one;two;three", CLI::detail::join(val, ";")); +} + +TEST(Join, Backward) { + std::vector<std::string> val{{"three", "two", "one"}}; + EXPECT_EQ("one,two,three", CLI::detail::rjoin(val)); + EXPECT_EQ("one;two;three", CLI::detail::rjoin(val, ";")); +} + +TEST(SplitUp, Simple) { + std::vector<std::string> oput = {"one", "two three"}; + std::string orig{R"(one "two three")"}; + std::vector<std::string> result = CLI::detail::split_up(orig); + EXPECT_EQ(oput, result); +} + +TEST(SplitUp, Layered) { + std::vector<std::string> output = {R"(one 'two three')"}; + std::string orig{R"("one 'two three'")"}; + std::vector<std::string> result = CLI::detail::split_up(orig); + EXPECT_EQ(output, result); +} + +TEST(SplitUp, Spaces) { + std::vector<std::string> oput = {"one", " two three"}; + std::string orig{R"( one " two three" )"}; + std::vector<std::string> result = CLI::detail::split_up(orig); + EXPECT_EQ(oput, result); +} + +TEST(SplitUp, BadStrings) { + std::vector<std::string> oput = {"one", " two three"}; + std::string orig{R"( one " two three )"}; + std::vector<std::string> result = CLI::detail::split_up(orig); + EXPECT_EQ(oput, result); + + oput = {"one", " two three"}; + orig = R"( one ' two three )"; + result = CLI::detail::split_up(orig); + EXPECT_EQ(oput, result); +} + +TEST(Types, TypeName) { + std::string int_name = CLI::detail::type_name<int>(); + EXPECT_EQ("INT", int_name); + + std::string int2_name = CLI::detail::type_name<short>(); + EXPECT_EQ("INT", int2_name); + + std::string uint_name = CLI::detail::type_name<unsigned char>(); + EXPECT_EQ("UINT", uint_name); + + std::string float_name = CLI::detail::type_name<double>(); + EXPECT_EQ("FLOAT", float_name); + + std::string vector_name = CLI::detail::type_name<std::vector<int>>(); + EXPECT_EQ("VECTOR", vector_name); + + std::string text_name = CLI::detail::type_name<std::string>(); + EXPECT_EQ("TEXT", text_name); + + std::string text2_name = CLI::detail::type_name<char *>(); + EXPECT_EQ("TEXT", text2_name); +} + +TEST(Types, OverflowSmall) { + char x; + auto strmax = std::to_string(INT8_MAX + 1); + EXPECT_FALSE(CLI::detail::lexical_cast(strmax, x)); + + unsigned char y; + strmax = std::to_string(UINT8_MAX + 1); + EXPECT_FALSE(CLI::detail::lexical_cast(strmax, y)); +} + +TEST(Types, LexicalCastInt) { + std::string signed_input = "-912"; + int x_signed; + EXPECT_TRUE(CLI::detail::lexical_cast(signed_input, x_signed)); + EXPECT_EQ(-912, x_signed); + + std::string unsigned_input = "912"; + unsigned int x_unsigned; + EXPECT_TRUE(CLI::detail::lexical_cast(unsigned_input, x_unsigned)); + EXPECT_EQ((unsigned int)912, x_unsigned); + + EXPECT_FALSE(CLI::detail::lexical_cast(signed_input, x_unsigned)); + + unsigned char y; + std::string overflow_input = std::to_string(UINT64_MAX) + "0"; + EXPECT_FALSE(CLI::detail::lexical_cast(overflow_input, y)); + + char y_signed; + EXPECT_FALSE(CLI::detail::lexical_cast(overflow_input, y_signed)); + + std::string bad_input = "hello"; + EXPECT_FALSE(CLI::detail::lexical_cast(bad_input, y)); + + std::string extra_input = "912i"; + EXPECT_FALSE(CLI::detail::lexical_cast(extra_input, y)); +} + +TEST(Types, LexicalCastDouble) { + std::string input = "9.12"; + long double x; + EXPECT_TRUE(CLI::detail::lexical_cast(input, x)); + EXPECT_FLOAT_EQ((float)9.12, (float)x); + + std::string bad_input = "hello"; + EXPECT_FALSE(CLI::detail::lexical_cast(bad_input, x)); + + std::string overflow_input = "1" + std::to_string(LDBL_MAX); + EXPECT_FALSE(CLI::detail::lexical_cast(overflow_input, x)); + + std::string extra_input = "9.12i"; + EXPECT_FALSE(CLI::detail::lexical_cast(extra_input, x)); +} + +TEST(Types, LexicalCastString) { + std::string input = "one"; + std::string output; + CLI::detail::lexical_cast(input, output); + EXPECT_EQ(input, output); +} + +TEST(Types, LexicalCastParsable) { + std::string input = "(4.2,7.3)"; + std::string fail_input = "4.2,7.3"; + std::string extra_input = "(4.2,7.3)e"; + + std::complex<double> output; + EXPECT_TRUE(CLI::detail::lexical_cast(input, output)); + EXPECT_EQ(output.real(), 4.2); // Doing this in one go sometimes has trouble + EXPECT_EQ(output.imag(), 7.3); // on clang + c++4.8 due to missing const + + EXPECT_FALSE(CLI::detail::lexical_cast(fail_input, output)); + EXPECT_FALSE(CLI::detail::lexical_cast(extra_input, output)); +} + +TEST(FixNewLines, BasicCheck) { + std::string input = "one\ntwo"; + std::string output = "one\n; two"; + std::string result = CLI::detail::fix_newlines("; ", input); + EXPECT_EQ(result, output); +} + +TEST(FixNewLines, EdgesCheck) { + std::string input = "\none\ntwo\n"; + std::string output = "\n; one\n; two\n; "; + std::string result = CLI::detail::fix_newlines("; ", input); + EXPECT_EQ(result, output); +} diff --git a/packages/CLI11/tests/IniTest.cpp b/packages/CLI11/tests/IniTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f2714506b01b29d9383849b9b804d00aaf2c2c3e --- /dev/null +++ b/packages/CLI11/tests/IniTest.cpp @@ -0,0 +1,766 @@ +#include "app_helper.hpp" + +#include <cstdio> +#include <sstream> +#include "gmock/gmock.h" + +using ::testing::HasSubstr; +using ::testing::Not; + +TEST(StringBased, First) { + std::stringstream ofile; + + ofile << "one=three" << std::endl; + ofile << "two=four" << std::endl; + + ofile.seekg(0, std::ios::beg); + + std::vector<CLI::detail::ini_ret_t> output = CLI::detail::parse_ini(ofile); + + EXPECT_EQ((size_t)2, output.size()); + EXPECT_EQ("one", output.at(0).name()); + EXPECT_EQ((size_t)1, output.at(0).inputs.size()); + EXPECT_EQ("three", output.at(0).inputs.at(0)); + EXPECT_EQ("two", output.at(1).name()); + EXPECT_EQ((size_t)1, output.at(1).inputs.size()); + EXPECT_EQ("four", output.at(1).inputs.at(0)); +} + +TEST(StringBased, FirstWithComments) { + std::stringstream ofile; + + ofile << ";this is a comment" << std::endl; + ofile << "one=three" << std::endl; + ofile << "two=four" << std::endl; + ofile << "; and another one" << std::endl; + + ofile.seekg(0, std::ios::beg); + + auto output = CLI::detail::parse_ini(ofile); + + EXPECT_EQ((size_t)2, output.size()); + EXPECT_EQ("one", output.at(0).name()); + EXPECT_EQ((size_t)1, output.at(0).inputs.size()); + EXPECT_EQ("three", output.at(0).inputs.at(0)); + EXPECT_EQ("two", output.at(1).name()); + EXPECT_EQ((size_t)1, output.at(1).inputs.size()); + EXPECT_EQ("four", output.at(1).inputs.at(0)); +} + +TEST(StringBased, Quotes) { + std::stringstream ofile; + + ofile << R"(one = "three")" << std::endl; + ofile << R"(two = 'four')" << std::endl; + ofile << R"(five = "six and seven")" << std::endl; + + ofile.seekg(0, std::ios::beg); + + auto output = CLI::detail::parse_ini(ofile); + + EXPECT_EQ((size_t)3, output.size()); + EXPECT_EQ("one", output.at(0).name()); + EXPECT_EQ((size_t)1, output.at(0).inputs.size()); + EXPECT_EQ("three", output.at(0).inputs.at(0)); + EXPECT_EQ("two", output.at(1).name()); + EXPECT_EQ((size_t)1, output.at(1).inputs.size()); + EXPECT_EQ("four", output.at(1).inputs.at(0)); + EXPECT_EQ("five", output.at(2).name()); + EXPECT_EQ((size_t)1, output.at(2).inputs.size()); + EXPECT_EQ("six and seven", output.at(2).inputs.at(0)); +} + +TEST(StringBased, Vector) { + std::stringstream ofile; + + ofile << "one = three" << std::endl; + ofile << "two = four" << std::endl; + ofile << "five = six and seven" << std::endl; + + ofile.seekg(0, std::ios::beg); + + auto output = CLI::detail::parse_ini(ofile); + + EXPECT_EQ((size_t)3, output.size()); + EXPECT_EQ("one", output.at(0).name()); + EXPECT_EQ((size_t)1, output.at(0).inputs.size()); + EXPECT_EQ("three", output.at(0).inputs.at(0)); + EXPECT_EQ("two", output.at(1).name()); + EXPECT_EQ((size_t)1, output.at(1).inputs.size()); + EXPECT_EQ("four", output.at(1).inputs.at(0)); + EXPECT_EQ("five", output.at(2).name()); + EXPECT_EQ((size_t)3, output.at(2).inputs.size()); + EXPECT_EQ("six", output.at(2).inputs.at(0)); + EXPECT_EQ("and", output.at(2).inputs.at(1)); + EXPECT_EQ("seven", output.at(2).inputs.at(2)); +} + +TEST(StringBased, Spaces) { + std::stringstream ofile; + + ofile << "one = three" << std::endl; + ofile << "two = four" << std::endl; + + ofile.seekg(0, std::ios::beg); + + auto output = CLI::detail::parse_ini(ofile); + + EXPECT_EQ((size_t)2, output.size()); + EXPECT_EQ("one", output.at(0).name()); + EXPECT_EQ((size_t)1, output.at(0).inputs.size()); + EXPECT_EQ("three", output.at(0).inputs.at(0)); + EXPECT_EQ("two", output.at(1).name()); + EXPECT_EQ((size_t)1, output.at(1).inputs.size()); + EXPECT_EQ("four", output.at(1).inputs.at(0)); +} + +TEST(StringBased, Sections) { + std::stringstream ofile; + + ofile << "one=three" << std::endl; + ofile << "[second]" << std::endl; + ofile << " two=four" << std::endl; + + ofile.seekg(0, std::ios::beg); + + auto output = CLI::detail::parse_ini(ofile); + + EXPECT_EQ((size_t)2, output.size()); + EXPECT_EQ("one", output.at(0).name()); + EXPECT_EQ((size_t)1, output.at(0).inputs.size()); + EXPECT_EQ("three", output.at(0).inputs.at(0)); + EXPECT_EQ("two", output.at(1).name()); + EXPECT_EQ("second", output.at(1).parent()); + EXPECT_EQ((size_t)1, output.at(1).inputs.size()); + EXPECT_EQ("four", output.at(1).inputs.at(0)); +} + +TEST(StringBased, SpacesSections) { + std::stringstream ofile; + + ofile << "one=three" << std::endl; + ofile << std::endl; + ofile << "[second]" << std::endl; + ofile << " " << std::endl; + ofile << " two=four" << std::endl; + + ofile.seekg(0, std::ios::beg); + + auto output = CLI::detail::parse_ini(ofile); + + EXPECT_EQ((size_t)2, output.size()); + EXPECT_EQ("one", output.at(0).name()); + EXPECT_EQ((size_t)1, output.at(0).inputs.size()); + EXPECT_EQ("three", output.at(0).inputs.at(0)); + EXPECT_EQ("two", output.at(1).name()); + EXPECT_EQ("second", output.at(1).parent()); + EXPECT_EQ((size_t)1, output.at(1).inputs.size()); + EXPECT_EQ("four", output.at(1).inputs.at(0)); +} + +TEST_F(TApp, IniNotRequired) { + + TempFile tmpini{"TestIniTmp.ini"}; + + app.set_config("--config", tmpini); + + { + std::ofstream out{tmpini}; + out << "[default]" << std::endl; + out << "two=99" << std::endl; + out << "three=3" << std::endl; + } + + int one = 0, two = 0, three = 0; + app.add_option("--one", one); + app.add_option("--two", two); + app.add_option("--three", three); + + args = {"--one=1"}; + + run(); + + EXPECT_EQ(1, one); + EXPECT_EQ(99, two); + EXPECT_EQ(3, three); + + app.reset(); + one = two = three = 0; + args = {"--one=1", "--two=2"}; + + run(); + + EXPECT_EQ(1, one); + EXPECT_EQ(2, two); + EXPECT_EQ(3, three); +} + +TEST_F(TApp, IniSuccessOnUnknownOption) { + TempFile tmpini{"TestIniTmp.ini"}; + + app.set_config("--config", tmpini); + app.allow_ini_extras(true); + + { + std::ofstream out{tmpini}; + out << "three=3" << std::endl; + out << "two=99" << std::endl; + } + + int two = 0; + app.add_option("--two", two); + EXPECT_NO_THROW(run()); + EXPECT_EQ(99, two); +} + +TEST_F(TApp, IniGetRemainingOption) { + TempFile tmpini{"TestIniTmp.ini"}; + + app.set_config("--config", tmpini); + app.allow_ini_extras(true); + + std::string ExtraOption = "three"; + std::string ExtraOptionValue = "3"; + { + std::ofstream out{tmpini}; + out << ExtraOption << "=" << ExtraOptionValue << std::endl; + out << "two=99" << std::endl; + } + + int two = 0; + app.add_option("--two", two); + EXPECT_NO_THROW(run()); + std::vector<std::string> ExpectedRemaining = {ExtraOption}; + EXPECT_EQ(app.remaining(), ExpectedRemaining); +} + +TEST_F(TApp, IniGetNoRemaining) { + TempFile tmpini{"TestIniTmp.ini"}; + + app.set_config("--config", tmpini); + app.allow_ini_extras(true); + + { + std::ofstream out{tmpini}; + out << "two=99" << std::endl; + } + + int two = 0; + app.add_option("--two", two); + EXPECT_NO_THROW(run()); + EXPECT_EQ(app.remaining().size(), (size_t)0); +} + +TEST_F(TApp, IniNotRequiredNotDefault) { + + TempFile tmpini{"TestIniTmp.ini"}; + TempFile tmpini2{"TestIniTmp2.ini"}; + + app.set_config("--config", tmpini); + + { + std::ofstream out{tmpini}; + out << "[default]" << std::endl; + out << "two=99" << std::endl; + out << "three=3" << std::endl; + } + + { + std::ofstream out{tmpini2}; + out << "[default]" << std::endl; + out << "two=98" << std::endl; + out << "three=4" << std::endl; + } + + int one = 0, two = 0, three = 0; + app.add_option("--one", one); + app.add_option("--two", two); + app.add_option("--three", three); + + run(); + + EXPECT_EQ(99, two); + EXPECT_EQ(3, three); + + app.reset(); + args = {"--config", tmpini2}; + run(); + + EXPECT_EQ(98, two); + EXPECT_EQ(4, three); +} + +TEST_F(TApp, IniRequiredNotFound) { + + std::string noini = "TestIniNotExist.ini"; + app.set_config("--config", noini, "", true); + + EXPECT_THROW(run(), CLI::FileError); +} + +TEST_F(TApp, IniNotRequiredPassedNotFound) { + + std::string noini = "TestIniNotExist.ini"; + app.set_config("--config", "", "", false); + + args = {"--config", noini}; + EXPECT_THROW(run(), CLI::FileError); +} + +TEST_F(TApp, IniOverwrite) { + + TempFile tmpini{"TestIniTmp.ini"}; + { + std::ofstream out{tmpini}; + out << "[default]" << std::endl; + out << "two=99" << std::endl; + } + + std::string orig = "filename_not_exist.ini"; + std::string next = "TestIniTmp.ini"; + app.set_config("--config", orig); + // Make sure this can be overwritten + app.set_config("--conf", next); + int two = 7; + app.add_option("--two", two); + + run(); + + EXPECT_EQ(99, two); +} + +TEST_F(TApp, IniRequired) { + + TempFile tmpini{"TestIniTmp.ini"}; + + app.set_config("--config", tmpini, "", true); + + { + std::ofstream out{tmpini}; + out << "[default]" << std::endl; + out << "two=99" << std::endl; + out << "three=3" << std::endl; + } + + int one = 0, two = 0, three = 0; + app.add_option("--one", one)->required(); + app.add_option("--two", two)->required(); + app.add_option("--three", three)->required(); + + args = {"--one=1"}; + + run(); + + app.reset(); + one = two = three = 0; + args = {"--one=1", "--two=2"}; + + run(); + + app.reset(); + args = {}; + + EXPECT_THROW(run(), CLI::RequiredError); + + app.reset(); + args = {"--two=2"}; + + EXPECT_THROW(run(), CLI::RequiredError); +} + +TEST_F(TApp, IniVector) { + + TempFile tmpini{"TestIniTmp.ini"}; + + app.set_config("--config", tmpini); + + { + std::ofstream out{tmpini}; + out << "[default]" << std::endl; + out << "two=2 3" << std::endl; + out << "three=1 2 3" << std::endl; + } + + std::vector<int> two, three; + app.add_option("--two", two)->expected(2)->required(); + app.add_option("--three", three)->required(); + + run(); + + EXPECT_EQ(std::vector<int>({2, 3}), two); + EXPECT_EQ(std::vector<int>({1, 2, 3}), three); +} + +TEST_F(TApp, IniLayered) { + + TempFile tmpini{"TestIniTmp.ini"}; + + app.set_config("--config", tmpini); + + { + std::ofstream out{tmpini}; + out << "[default]" << std::endl; + out << "val=1" << std::endl; + out << "[subcom]" << std::endl; + out << "val=2" << std::endl; + out << "subsubcom.val=3" << std::endl; + } + + int one = 0, two = 0, three = 0; + app.add_option("--val", one); + auto subcom = app.add_subcommand("subcom"); + subcom->add_option("--val", two); + auto subsubcom = subcom->add_subcommand("subsubcom"); + subsubcom->add_option("--val", three); + + ASSERT_NO_THROW(run()); + + EXPECT_EQ(1, one); + EXPECT_EQ(2, two); + EXPECT_EQ(3, three); +} + +TEST_F(TApp, IniFailure) { + + TempFile tmpini{"TestIniTmp.ini"}; + + app.set_config("--config", tmpini); + + { + std::ofstream out{tmpini}; + out << "[default]" << std::endl; + out << "val=1" << std::endl; + } + + EXPECT_THROW(run(), CLI::INIError); +} + +TEST_F(TApp, IniConfigurable) { + + TempFile tmpini{"TestIniTmp.ini"}; + + app.set_config("--config", tmpini); + bool value; + app.add_flag("--val", value)->configurable(true); + + { + std::ofstream out{tmpini}; + out << "[default]" << std::endl; + out << "val=1" << std::endl; + } + + EXPECT_NO_THROW(run()); + EXPECT_TRUE(value); +} + +TEST_F(TApp, IniNotConfigurable) { + + TempFile tmpini{"TestIniTmp.ini"}; + + app.set_config("--config", tmpini); + bool value; + app.add_flag("--val", value)->configurable(false); + + { + std::ofstream out{tmpini}; + out << "[default]" << std::endl; + out << "val=1" << std::endl; + } + + EXPECT_THROW(run(), CLI::INIError); +} + +TEST_F(TApp, IniSubFailure) { + + TempFile tmpini{"TestIniTmp.ini"}; + + app.add_subcommand("other"); + app.set_config("--config", tmpini); + + { + std::ofstream out{tmpini}; + out << "[other]" << std::endl; + out << "val=1" << std::endl; + } + + EXPECT_THROW(run(), CLI::INIError); +} + +TEST_F(TApp, IniNoSubFailure) { + + TempFile tmpini{"TestIniTmp.ini"}; + + app.set_config("--config", tmpini); + + { + std::ofstream out{tmpini}; + out << "[other]" << std::endl; + out << "val=1" << std::endl; + } + + EXPECT_THROW(run(), CLI::INIError); +} + +TEST_F(TApp, IniFlagConvertFailure) { + + TempFile tmpini{"TestIniTmp.ini"}; + + app.add_flag("--flag"); + app.set_config("--config", tmpini); + + { + std::ofstream out{tmpini}; + out << "flag=moobook" << std::endl; + } + + EXPECT_THROW(run(), CLI::ConversionError); +} + +TEST_F(TApp, IniFlagNumbers) { + + TempFile tmpini{"TestIniTmp.ini"}; + + bool boo; + app.add_flag("--flag", boo); + app.set_config("--config", tmpini); + + { + std::ofstream out{tmpini}; + out << "flag=3" << std::endl; + } + + EXPECT_NO_THROW(run()); + EXPECT_TRUE(boo); +} + +TEST_F(TApp, IniFlagDual) { + + TempFile tmpini{"TestIniTmp.ini"}; + + bool boo; + app.add_flag("--flag", boo); + app.set_config("--config", tmpini); + + { + std::ofstream out{tmpini}; + out << "flag=1 1" << std::endl; + } + + EXPECT_THROW(run(), CLI::ConversionError); +} + +TEST_F(TApp, IniFlagText) { + + TempFile tmpini{"TestIniTmp.ini"}; + + bool flag1, flag2, flag3, flag4; + app.add_flag("--flag1", flag1); + app.add_flag("--flag2", flag2); + app.add_flag("--flag3", flag3); + app.add_flag("--flag4", flag4); + app.set_config("--config", tmpini); + + { + std::ofstream out{tmpini}; + out << "flag1=true" << std::endl; + out << "flag2=on" << std::endl; + out << "flag3=off" << std::endl; + out << "flag4=1" << std::endl; + } + + run(); + + EXPECT_TRUE(flag1); + EXPECT_TRUE(flag2); + EXPECT_FALSE(flag3); + EXPECT_TRUE(flag4); +} + +TEST_F(TApp, IniFlags) { + TempFile tmpini{"TestIniTmp.ini"}; + app.set_config("--config", tmpini); + + { + std::ofstream out{tmpini}; + out << "[default]" << std::endl; + out << "two=2" << std::endl; + out << "three=true" << std::endl; + out << "four=on" << std::endl; + out << "five" << std::endl; + } + + int two; + bool three, four, five; + app.add_flag("--two", two); + app.add_flag("--three", three); + app.add_flag("--four", four); + app.add_flag("--five", five); + + run(); + + EXPECT_EQ(2, two); + EXPECT_EQ(true, three); + EXPECT_EQ(true, four); + EXPECT_EQ(true, five); +} + +TEST_F(TApp, IniOutputSimple) { + + int v; + app.add_option("--simple", v); + + args = {"--simple=3"}; + + run(); + + std::string str = app.config_to_str(); + EXPECT_EQ("simple=3\n", str); +} + +TEST_F(TApp, IniOutputNoConfigurable) { + + int v1, v2; + app.add_option("--simple", v1); + app.add_option("--noconf", v2)->configurable(false); + + args = {"--simple=3", "--noconf=2"}; + + run(); + + std::string str = app.config_to_str(); + EXPECT_EQ("simple=3\n", str); +} + +TEST_F(TApp, IniOutputShortSingleDescription) { + std::string flag = "some_flag"; + std::string description = "Some short description."; + app.add_flag("--" + flag, description); + + run(); + + std::string str = app.config_to_str(true, "", true); + EXPECT_THAT(str, HasSubstr("; " + description + "\n" + flag + "=false\n")); +} + +TEST_F(TApp, IniOutputShortDoubleDescription) { + std::string flag1 = "flagnr1"; + std::string flag2 = "flagnr2"; + std::string description1 = "First description."; + std::string description2 = "Second description."; + app.add_flag("--" + flag1, description1); + app.add_flag("--" + flag2, description2); + + run(); + + std::string str = app.config_to_str(true, "", true); + EXPECT_EQ(str, "; " + description1 + "\n" + flag1 + "=false\n\n; " + description2 + "\n" + flag2 + "=false\n"); +} + +TEST_F(TApp, IniOutputMultiLineDescription) { + std::string flag = "some_flag"; + std::string description = "Some short description.\nThat has lines."; + app.add_flag("--" + flag, description); + + run(); + + std::string str = app.config_to_str(true, "", true); + EXPECT_THAT(str, HasSubstr("; Some short description.\n")); + EXPECT_THAT(str, HasSubstr("; That has lines.\n")); + EXPECT_THAT(str, HasSubstr(flag + "=false\n")); +} + +TEST_F(TApp, IniOutputVector) { + + std::vector<int> v; + app.add_option("--vector", v); + + args = {"--vector", "1", "2", "3"}; + + run(); + + std::string str = app.config_to_str(); + EXPECT_EQ("vector=1 2 3\n", str); +} + +TEST_F(TApp, IniOutputFlag) { + + int v, q; + app.add_option("--simple", v); + app.add_flag("--nothing"); + app.add_flag("--onething"); + app.add_flag("--something", q); + + args = {"--simple=3", "--onething", "--something", "--something"}; + + run(); + + std::string str = app.config_to_str(); + EXPECT_THAT(str, HasSubstr("simple=3")); + EXPECT_THAT(str, Not(HasSubstr("nothing"))); + EXPECT_THAT(str, HasSubstr("onething=true")); + EXPECT_THAT(str, HasSubstr("something=2")); + + str = app.config_to_str(true); + EXPECT_THAT(str, HasSubstr("nothing")); +} + +TEST_F(TApp, IniOutputSet) { + + int v; + app.add_set("--simple", v, {1, 2, 3}); + + args = {"--simple=2"}; + + run(); + + std::string str = app.config_to_str(); + EXPECT_THAT(str, HasSubstr("simple=2")); +} + +TEST_F(TApp, IniOutputDefault) { + + int v = 7; + app.add_option("--simple", v, "", true); + + run(); + + std::string str = app.config_to_str(); + EXPECT_THAT(str, Not(HasSubstr("simple=7"))); + + str = app.config_to_str(true); + EXPECT_THAT(str, HasSubstr("simple=7")); +} + +TEST_F(TApp, IniOutputSubcom) { + + app.add_flag("--simple"); + auto subcom = app.add_subcommand("other"); + subcom->add_flag("--newer"); + + args = {"--simple", "other", "--newer"}; + run(); + + std::string str = app.config_to_str(); + EXPECT_THAT(str, HasSubstr("simple=true")); + EXPECT_THAT(str, HasSubstr("other.newer=true")); +} + +TEST_F(TApp, IniQuotedOutput) { + + std::string val1; + app.add_option("--val1", val1); + + std::string val2; + app.add_option("--val2", val2); + + args = {"--val1", "I am a string", "--val2", R"(I am a "confusing" string)"}; + + run(); + + EXPECT_EQ("I am a string", val1); + EXPECT_EQ("I am a \"confusing\" string", val2); + + std::string str = app.config_to_str(); + EXPECT_THAT(str, HasSubstr("val1=\"I am a string\"")); + EXPECT_THAT(str, HasSubstr("val2='I am a \"confusing\" string'")); +} diff --git a/packages/CLI11/tests/NewParseTest.cpp b/packages/CLI11/tests/NewParseTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5c38870fc7d650cbe865fb6a19cb4c15922814a5 --- /dev/null +++ b/packages/CLI11/tests/NewParseTest.cpp @@ -0,0 +1,99 @@ +#include "app_helper.hpp" +#include "gmock/gmock.h" +#include <complex> + +using ::testing::HasSubstr; + +using cx = std::complex<double>; + +CLI::Option * +add_option(CLI::App &app, std::string name, cx &variable, std::string description = "", bool defaulted = false) { + CLI::callback_t fun = [&variable](CLI::results_t res) { + double x, y; + bool worked = CLI::detail::lexical_cast(res[0], x) && CLI::detail::lexical_cast(res[1], y); + if(worked) + variable = cx(x, y); + return worked; + }; + + CLI::Option *opt = app.add_option(name, fun, description, defaulted); + opt->set_custom_option("COMPLEX", 2); + if(defaulted) { + std::stringstream out; + out << variable; + opt->set_default_str(out.str()); + } + return opt; +} + +TEST_F(TApp, AddingComplexParser) { + + cx comp{0, 0}; + add_option(app, "-c,--complex", comp); + args = {"-c", "1.5", "2.5"}; + + run(); + + EXPECT_EQ(1.5, comp.real()); + EXPECT_EQ(2.5, comp.imag()); +} + +TEST_F(TApp, DefaultComplex) { + + cx comp{1, 2}; + add_option(app, "-c,--complex", comp, "", true); + args = {"-c", "4", "3"}; + + std::string help = app.help(); + EXPECT_THAT(help, HasSubstr("1")); + EXPECT_THAT(help, HasSubstr("2")); + + EXPECT_EQ(1, comp.real()); + EXPECT_EQ(2, comp.imag()); + + run(); + + EXPECT_EQ(4, comp.real()); + EXPECT_EQ(3, comp.imag()); +} + +TEST_F(TApp, BuiltinComplex) { + cx comp{1, 2}; + app.add_complex("-c,--complex", comp, "", true); + + args = {"-c", "4", "3"}; + + std::string help = app.help(); + EXPECT_THAT(help, HasSubstr("1")); + EXPECT_THAT(help, HasSubstr("2")); + EXPECT_THAT(help, HasSubstr("COMPLEX")); + + EXPECT_EQ(1, comp.real()); + EXPECT_EQ(2, comp.imag()); + + run(); + + EXPECT_EQ(4, comp.real()); + EXPECT_EQ(3, comp.imag()); +} + +TEST_F(TApp, BuiltinComplexIgnoreI) { + cx comp{1, 2}; + app.add_complex("-c,--complex", comp); + + args = {"-c", "4", "3i"}; + + run(); + + EXPECT_EQ(4, comp.real()); + EXPECT_EQ(3, comp.imag()); +} + +TEST_F(TApp, BuiltinComplexFail) { + cx comp{1, 2}; + app.add_complex("-c,--complex", comp); + + args = {"-c", "4"}; + + EXPECT_THROW(run(), CLI::ArgumentMismatch); +} diff --git a/packages/CLI11/tests/SimpleTest.cpp b/packages/CLI11/tests/SimpleTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..bc1f1ba0db655f6b2f25226ac05dab07c76193d1 --- /dev/null +++ b/packages/CLI11/tests/SimpleTest.cpp @@ -0,0 +1,28 @@ +#ifdef CLI_SINGLE_FILE +#include "CLI11.hpp" +#else +#include "CLI/CLI.hpp" +#endif + +#include "gtest/gtest.h" + +using input_t = std::vector<std::string>; + +TEST(Basic, Empty) { + + { + CLI::App app; + input_t simpleput; + app.parse(simpleput); + } + { + CLI::App app; + input_t spare = {"spare"}; + EXPECT_THROW(app.parse(spare), CLI::ExtrasError); + } + { + CLI::App app; + input_t simpleput; + app.parse(simpleput); + } +} diff --git a/packages/CLI11/tests/SubcommandTest.cpp b/packages/CLI11/tests/SubcommandTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5f163f23d41d3d224cf34c97c4d9626c863cb8fe --- /dev/null +++ b/packages/CLI11/tests/SubcommandTest.cpp @@ -0,0 +1,731 @@ +#include "app_helper.hpp" + +#include "gtest/gtest.h" +#include "gmock/gmock.h" + +using ::testing::HasSubstr; +using ::testing::Not; + +using vs_t = std::vector<std::string>; + +TEST_F(TApp, BasicSubcommands) { + auto sub1 = app.add_subcommand("sub1"); + auto sub2 = app.add_subcommand("sub2"); + + EXPECT_EQ(sub1->get_parent(), &app); + + EXPECT_EQ(sub1, app.get_subcommand(sub1)); + EXPECT_EQ(sub1, app.get_subcommand("sub1")); + EXPECT_THROW(app.get_subcommand("sub3"), CLI::OptionNotFound); + + run(); + EXPECT_EQ((size_t)0, app.get_subcommands().size()); + + app.reset(); + args = {"sub1"}; + run(); + EXPECT_EQ(sub1, app.get_subcommands().at(0)); + + app.reset(); + EXPECT_EQ((size_t)0, app.get_subcommands().size()); + + args = {"sub2"}; + run(); + EXPECT_EQ((size_t)1, app.get_subcommands().size()); + EXPECT_EQ(sub2, app.get_subcommands().at(0)); + + app.reset(); + args = {"SUb2"}; + EXPECT_THROW(run(), CLI::ExtrasError); + + app.reset(); + args = {"SUb2"}; + try { + run(); + } catch(const CLI::ExtrasError &e) { + EXPECT_THAT(e.what(), HasSubstr("SUb2")); + } + + app.reset(); + args = {"sub1", "extra"}; + try { + run(); + } catch(const CLI::ExtrasError &e) { + EXPECT_THAT(e.what(), HasSubstr("extra")); + } +} + +TEST_F(TApp, MultiSubFallthrough) { + + // No explicit fallthrough + auto sub1 = app.add_subcommand("sub1"); + auto sub2 = app.add_subcommand("sub2"); + + args = {"sub1", "sub2"}; + run(); + EXPECT_TRUE(app.got_subcommand("sub1")); + EXPECT_TRUE(app.got_subcommand(sub1)); + EXPECT_TRUE(*sub1); + EXPECT_TRUE(sub1->parsed()); + + EXPECT_TRUE(app.got_subcommand("sub2")); + EXPECT_TRUE(app.got_subcommand(sub2)); + EXPECT_TRUE(*sub2); + + app.reset(); + app.require_subcommand(); + + run(); + + app.reset(); + app.require_subcommand(2); + + run(); + + app.reset(); + app.require_subcommand(1); + + EXPECT_THROW(run(), CLI::ExtrasError); + + app.reset(); + args = {"sub1"}; + run(); + + EXPECT_TRUE(app.got_subcommand("sub1")); + EXPECT_FALSE(app.got_subcommand("sub2")); + + EXPECT_TRUE(*sub1); + EXPECT_FALSE(*sub2); + EXPECT_FALSE(sub2->parsed()); + + EXPECT_THROW(app.got_subcommand("sub3"), CLI::OptionNotFound); +} + +TEST_F(TApp, RequiredAndSubcoms) { // #23 + + std::string baz; + app.add_option("baz", baz, "Baz Description", true)->required(); + auto foo = app.add_subcommand("foo"); + auto bar = app.add_subcommand("bar"); + + args = {"bar", "foo"}; + EXPECT_NO_THROW(run()); + EXPECT_TRUE(*foo); + EXPECT_FALSE(*bar); + EXPECT_EQ(baz, "bar"); + + app.reset(); + args = {"foo"}; + EXPECT_NO_THROW(run()); + EXPECT_FALSE(*foo); + EXPECT_EQ(baz, "foo"); + + app.reset(); + args = {"foo", "foo"}; + EXPECT_NO_THROW(run()); + EXPECT_TRUE(*foo); + EXPECT_EQ(baz, "foo"); + + app.reset(); + args = {"foo", "other"}; + EXPECT_THROW(run(), CLI::ExtrasError); +} + +TEST_F(TApp, RequiredAndSubcomFallthrough) { + + std::string baz; + app.add_option("baz", baz)->required(); + app.add_subcommand("foo"); + auto bar = app.add_subcommand("bar"); + app.fallthrough(); + + args = {"other", "bar"}; + run(); + EXPECT_TRUE(bar); + EXPECT_EQ(baz, "other"); + + app.reset(); + args = {"bar", "other2"}; + EXPECT_THROW(run(), CLI::ExtrasError); +} + +TEST_F(TApp, FooFooProblem) { + + std::string baz_str, other_str; + auto baz = app.add_option("baz", baz_str); + auto foo = app.add_subcommand("foo"); + auto other = foo->add_option("other", other_str); + + args = {"foo", "foo"}; + run(); + EXPECT_TRUE(*foo); + EXPECT_FALSE(*baz); + EXPECT_TRUE(*other); + EXPECT_EQ(baz_str, ""); + EXPECT_EQ(other_str, "foo"); + + app.reset(); + baz_str = ""; + other_str = ""; + baz->required(); + run(); + EXPECT_TRUE(*foo); + EXPECT_TRUE(*baz); + EXPECT_FALSE(*other); + EXPECT_EQ(baz_str, "foo"); + EXPECT_EQ(other_str, ""); +} + +TEST_F(TApp, Callbacks) { + auto sub1 = app.add_subcommand("sub1"); + sub1->set_callback([]() { throw CLI::Success(); }); + auto sub2 = app.add_subcommand("sub2"); + bool val = false; + sub2->set_callback([&val]() { val = true; }); + + args = {"sub2"}; + EXPECT_FALSE(val); + run(); + EXPECT_TRUE(val); +} + +TEST_F(TApp, RuntimeErrorInCallback) { + auto sub1 = app.add_subcommand("sub1"); + sub1->set_callback([]() { throw CLI::RuntimeError(); }); + auto sub2 = app.add_subcommand("sub2"); + sub2->set_callback([]() { throw CLI::RuntimeError(2); }); + + args = {"sub1"}; + EXPECT_THROW(run(), CLI::RuntimeError); + + app.reset(); + args = {"sub1"}; + try { + run(); + } catch(const CLI::RuntimeError &e) { + EXPECT_EQ(1, e.get_exit_code()); + } + + app.reset(); + args = {"sub2"}; + EXPECT_THROW(run(), CLI::RuntimeError); + + app.reset(); + args = {"sub2"}; + try { + run(); + } catch(const CLI::RuntimeError &e) { + EXPECT_EQ(2, e.get_exit_code()); + } +} + +TEST_F(TApp, NoFallThroughOpts) { + int val = 1; + app.add_option("--val", val); + + app.add_subcommand("sub"); + + args = {"sub", "--val", "2"}; + EXPECT_THROW(run(), CLI::ExtrasError); +} + +TEST_F(TApp, NoFallThroughPositionals) { + int val = 1; + app.add_option("val", val); + + app.add_subcommand("sub"); + + args = {"sub", "2"}; + EXPECT_THROW(run(), CLI::ExtrasError); +} + +TEST_F(TApp, FallThroughRegular) { + app.fallthrough(); + int val = 1; + app.add_option("--val", val); + + app.add_subcommand("sub"); + + args = {"sub", "--val", "2"}; + // Should not throw + run(); +} + +TEST_F(TApp, FallThroughShort) { + app.fallthrough(); + int val = 1; + app.add_option("-v", val); + + app.add_subcommand("sub"); + + args = {"sub", "-v", "2"}; + // Should not throw + run(); +} + +TEST_F(TApp, FallThroughPositional) { + app.fallthrough(); + int val = 1; + app.add_option("val", val); + + app.add_subcommand("sub"); + + args = {"sub", "2"}; + // Should not throw + run(); +} + +TEST_F(TApp, FallThroughEquals) { + app.fallthrough(); + int val = 1; + app.add_option("--val", val); + + app.add_subcommand("sub"); + + args = {"sub", "--val=2"}; + // Should not throw + run(); +} + +TEST_F(TApp, EvilParseFallthrough) { + app.fallthrough(); + int val1 = 0, val2 = 0; + app.add_option("--val1", val1); + + auto sub = app.add_subcommand("sub"); + sub->add_option("val2", val2); + + args = {"sub", "--val1", "1", "2"}; + // Should not throw + run(); + + EXPECT_EQ(1, val1); + EXPECT_EQ(2, val2); +} + +TEST_F(TApp, CallbackOrdering) { + app.fallthrough(); + int val = 1, sub_val = 0; + app.add_option("--val", val); + + auto sub = app.add_subcommand("sub"); + sub->set_callback([&val, &sub_val]() { sub_val = val; }); + + args = {"sub", "--val=2"}; + run(); + EXPECT_EQ(2, val); + EXPECT_EQ(2, sub_val); + + app.reset(); + args = {"--val=2", "sub"}; + run(); + EXPECT_EQ(2, val); + EXPECT_EQ(2, sub_val); +} + +TEST_F(TApp, RequiredSubCom) { + app.add_subcommand("sub1"); + app.add_subcommand("sub2"); + + app.require_subcommand(); + + EXPECT_THROW(run(), CLI::RequiredError); + + app.reset(); + + args = {"sub1"}; + + run(); +} + +TEST_F(TApp, SubComExtras) { + app.allow_extras(); + auto sub = app.add_subcommand("sub"); + + args = {"extra", "sub"}; + run(); + EXPECT_EQ(app.remaining(), std::vector<std::string>({"extra"})); + EXPECT_EQ(sub->remaining(), std::vector<std::string>()); + + app.reset(); + + args = {"extra1", "extra2", "sub"}; + run(); + EXPECT_EQ(app.remaining(), std::vector<std::string>({"extra1", "extra2"})); + EXPECT_EQ(sub->remaining(), std::vector<std::string>()); + + app.reset(); + + args = {"sub", "extra1", "extra2"}; + run(); + EXPECT_EQ(app.remaining(), std::vector<std::string>()); + EXPECT_EQ(sub->remaining(), std::vector<std::string>({"extra1", "extra2"})); + + app.reset(); + + args = {"extra1", "extra2", "sub", "extra3", "extra4"}; + run(); + EXPECT_EQ(app.remaining(), std::vector<std::string>({"extra1", "extra2"})); + EXPECT_EQ(app.remaining(true), std::vector<std::string>({"extra1", "extra2", "extra3", "extra4"})); + EXPECT_EQ(sub->remaining(), std::vector<std::string>({"extra3", "extra4"})); +} + +TEST_F(TApp, Required1SubCom) { + app.require_subcommand(1); + app.add_subcommand("sub1"); + app.add_subcommand("sub2"); + app.add_subcommand("sub3"); + + EXPECT_THROW(run(), CLI::RequiredError); + + app.reset(); + args = {"sub1"}; + run(); + + app.reset(); + args = {"sub1", "sub2"}; + EXPECT_THROW(run(), CLI::ExtrasError); +} + +TEST_F(TApp, BadSubcomSearch) { + + auto one = app.add_subcommand("one"); + auto two = one->add_subcommand("two"); + + EXPECT_THROW(app.get_subcommand(two), CLI::OptionNotFound); +} + +TEST_F(TApp, PrefixProgram) { + + app.prefix_command(); + + app.add_flag("--simple"); + + args = {"--simple", "other", "--simple", "--mine"}; + run(); + + EXPECT_EQ(app.remaining(), std::vector<std::string>({"other", "--simple", "--mine"})); +} + +TEST_F(TApp, PrefixSubcom) { + auto subc = app.add_subcommand("subc"); + subc->prefix_command(); + + app.add_flag("--simple"); + + args = {"--simple", "subc", "other", "--simple", "--mine"}; + run(); + + EXPECT_EQ(app.remaining_size(), (size_t)0); + EXPECT_EQ(app.remaining_size(true), (size_t)3); + EXPECT_EQ(subc->remaining(), std::vector<std::string>({"other", "--simple", "--mine"})); +} + +struct SubcommandProgram : public TApp { + + CLI::App *start; + CLI::App *stop; + + int dummy; + std::string file; + int count; + + SubcommandProgram() { + start = app.add_subcommand("start", "Start prog"); + stop = app.add_subcommand("stop", "Stop prog"); + + app.add_flag("-d", dummy, "My dummy var"); + start->add_option("-f,--file", file, "File name"); + stop->add_flag("-c,--count", count, "Some flag opt"); + } +}; + +TEST_F(SubcommandProgram, Working) { + args = {"-d", "start", "-ffilename"}; + + run(); + + EXPECT_EQ(1, dummy); + EXPECT_EQ(start, app.get_subcommands().at(0)); + EXPECT_EQ("filename", file); +} + +TEST_F(SubcommandProgram, Spare) { + args = {"extra", "-d", "start", "-ffilename"}; + + EXPECT_THROW(run(), CLI::ExtrasError); +} + +TEST_F(SubcommandProgram, SpareSub) { + args = {"-d", "start", "spare", "-ffilename"}; + + EXPECT_THROW(run(), CLI::ExtrasError); +} + +TEST_F(SubcommandProgram, Multiple) { + args = {"-d", "start", "-ffilename", "stop"}; + + run(); + EXPECT_EQ((size_t)2, app.get_subcommands().size()); + EXPECT_EQ(1, dummy); + EXPECT_EQ("filename", file); +} + +TEST_F(SubcommandProgram, MultipleOtherOrder) { + args = {"start", "-d", "-ffilename", "stop"}; + + EXPECT_THROW(run(), CLI::ExtrasError); +} + +TEST_F(SubcommandProgram, MultipleArgs) { + args = {"start", "stop"}; + + run(); + + EXPECT_EQ((size_t)2, app.get_subcommands().size()); +} + +TEST_F(SubcommandProgram, CaseCheck) { + args = {"Start"}; + EXPECT_THROW(run(), CLI::ExtrasError); + + app.reset(); + args = {"start"}; + run(); + + app.reset(); + start->ignore_case(); + run(); + + app.reset(); + args = {"Start"}; + run(); +} + +TEST_F(TApp, SubcomInheritCaseCheck) { + app.ignore_case(); + auto sub1 = app.add_subcommand("sub1"); + auto sub2 = app.add_subcommand("sub2"); + + run(); + EXPECT_EQ((size_t)0, app.get_subcommands().size()); + + app.reset(); + args = {"SuB1"}; + run(); + EXPECT_EQ(sub1, app.get_subcommands().at(0)); + + app.reset(); + EXPECT_EQ((size_t)0, app.get_subcommands().size()); + + args = {"sUb2"}; + run(); + EXPECT_EQ(sub2, app.get_subcommands().at(0)); +} + +TEST_F(SubcommandProgram, HelpOrder) { + + args = {"-h"}; + EXPECT_THROW(run(), CLI::CallForHelp); + + args = {"start", "-h"}; + EXPECT_THROW(run(), CLI::CallForHelp); + + args = {"-h", "start"}; + EXPECT_THROW(run(), CLI::CallForHelp); +} + +TEST_F(SubcommandProgram, Callbacks) { + + start->set_callback([]() { throw CLI::Success(); }); + + run(); + + app.reset(); + + args = {"start"}; + + EXPECT_THROW(run(), CLI::Success); +} + +TEST_F(SubcommandProgram, Groups) { + + std::string help = app.help(); + EXPECT_THAT(help, Not(HasSubstr("More Commands:"))); + EXPECT_THAT(help, HasSubstr("Subcommands:")); + + start->group("More Commands"); + help = app.help(); + EXPECT_THAT(help, HasSubstr("More Commands:")); + EXPECT_THAT(help, HasSubstr("Subcommands:")); + + // Case is ignored but for the first subcommand in a group. + stop->group("more commands"); + help = app.help(); + EXPECT_THAT(help, HasSubstr("More Commands:")); + EXPECT_THAT(help, Not(HasSubstr("Subcommands:"))); +} + +TEST_F(SubcommandProgram, ExtrasErrors) { + + args = {"one", "two", "start", "three", "four"}; + EXPECT_THROW(run(), CLI::ExtrasError); + app.reset(); + + args = {"start", "three", "four"}; + EXPECT_THROW(run(), CLI::ExtrasError); + app.reset(); + + args = {"one", "two"}; + EXPECT_THROW(run(), CLI::ExtrasError); + app.reset(); +} + +TEST_F(SubcommandProgram, OrderedExtras) { + + app.allow_extras(); + args = {"one", "two", "start", "three", "four"}; + EXPECT_THROW(run(), CLI::ExtrasError); + app.reset(); + + start->allow_extras(); + + run(); + + EXPECT_EQ(app.remaining(), std::vector<std::string>({"one", "two"})); + EXPECT_EQ(start->remaining(), std::vector<std::string>({"three", "four"})); + EXPECT_EQ(app.remaining(true), std::vector<std::string>({"one", "two", "three", "four"})); + + app.reset(); + args = {"one", "two", "start", "three", "--", "four"}; + + run(); + + EXPECT_EQ(app.remaining(), std::vector<std::string>({"one", "two"})); + EXPECT_EQ(start->remaining(), std::vector<std::string>({"three", "--", "four"})); + EXPECT_EQ(app.remaining(true), std::vector<std::string>({"one", "two", "three", "--", "four"})); +} + +TEST_F(SubcommandProgram, MixedOrderExtras) { + + app.allow_extras(); + start->allow_extras(); + stop->allow_extras(); + + args = {"one", "two", "start", "three", "four", "stop", "five", "six"}; + run(); + + EXPECT_EQ(app.remaining(), std::vector<std::string>({"one", "two"})); + EXPECT_EQ(start->remaining(), std::vector<std::string>({"three", "four"})); + EXPECT_EQ(stop->remaining(), std::vector<std::string>({"five", "six"})); + EXPECT_EQ(app.remaining(true), std::vector<std::string>({"one", "two", "three", "four", "five", "six"})); + + app.reset(); + args = {"one", "two", "stop", "three", "four", "start", "five", "six"}; + run(); + + EXPECT_EQ(app.remaining(), std::vector<std::string>({"one", "two"})); + EXPECT_EQ(stop->remaining(), std::vector<std::string>({"three", "four"})); + EXPECT_EQ(start->remaining(), std::vector<std::string>({"five", "six"})); + EXPECT_EQ(app.remaining(true), std::vector<std::string>({"one", "two", "three", "four", "five", "six"})); +} + +TEST_F(SubcommandProgram, CallbackOrder) { + std::vector<int> callback_order; + start->set_callback([&callback_order]() { callback_order.push_back(1); }); + stop->set_callback([&callback_order]() { callback_order.push_back(2); }); + + args = {"start", "stop"}; + run(); + EXPECT_EQ(callback_order, std::vector<int>({1, 2})); + + app.reset(); + callback_order.clear(); + + args = {"stop", "start"}; + run(); + EXPECT_EQ(callback_order, std::vector<int>({2, 1})); +} + +struct ManySubcommands : public TApp { + + CLI::App *sub1; + CLI::App *sub2; + CLI::App *sub3; + CLI::App *sub4; + + ManySubcommands() { + app.allow_extras(); + sub1 = app.add_subcommand("sub1"); + sub2 = app.add_subcommand("sub2"); + sub3 = app.add_subcommand("sub3"); + sub4 = app.add_subcommand("sub4"); + args = {"sub1", "sub2", "sub3"}; + } +}; + +TEST_F(ManySubcommands, Required1Exact) { + app.require_subcommand(1); + + run(); + EXPECT_EQ(sub1->remaining(), vs_t({"sub2", "sub3"})); + EXPECT_EQ(app.remaining(true), vs_t({"sub2", "sub3"})); +} + +TEST_F(ManySubcommands, Required2Exact) { + app.require_subcommand(2); + + run(); + EXPECT_EQ(sub2->remaining(), vs_t({"sub3"})); +} + +TEST_F(ManySubcommands, Required4Failure) { + app.require_subcommand(4); + + EXPECT_THROW(run(), CLI::RequiredError); +} + +TEST_F(ManySubcommands, Required1Fuzzy) { + + app.require_subcommand(0, 1); + + run(); + EXPECT_EQ(sub1->remaining(), vs_t({"sub2", "sub3"})); + + app.reset(); + app.require_subcommand(-1); + + run(); + EXPECT_EQ(sub1->remaining(), vs_t({"sub2", "sub3"})); +} + +TEST_F(ManySubcommands, Required2Fuzzy) { + app.require_subcommand(0, 2); + + run(); + EXPECT_EQ(sub2->remaining(), vs_t({"sub3"})); + EXPECT_EQ(app.remaining(true), vs_t({"sub3"})); + + app.reset(); + app.require_subcommand(-2); + + run(); + EXPECT_EQ(sub2->remaining(), vs_t({"sub3"})); +} + +TEST_F(ManySubcommands, Unlimited) { + run(); + EXPECT_EQ(app.remaining(true), vs_t()); + + app.reset(); + app.require_subcommand(); + + run(); + EXPECT_EQ(app.remaining(true), vs_t()); + + app.reset(); + app.require_subcommand(2, 0); // 2 or more + + run(); + EXPECT_EQ(app.remaining(true), vs_t()); +} diff --git a/packages/CLI11/tests/TimerTest.cpp b/packages/CLI11/tests/TimerTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8e03088d7582e5c8c6611f64d30e9f2b38cfbb5d --- /dev/null +++ b/packages/CLI11/tests/TimerTest.cpp @@ -0,0 +1,64 @@ +#include "gtest/gtest.h" +#include "gmock/gmock.h" +#include "CLI/Timer.hpp" +#include <string> +#include <chrono> +#include <thread> +#include <sstream> + +using ::testing::HasSubstr; + +TEST(Timer, MSTimes) { + CLI::Timer timer{"My Timer"}; + std::this_thread::sleep_for(std::chrono::milliseconds(123)); + std::string output = timer.to_string(); + std::string new_output = (timer / 1000000).to_string(); + EXPECT_THAT(output, HasSubstr("My Timer")); + EXPECT_THAT(output, HasSubstr(" ms")); + EXPECT_THAT(new_output, HasSubstr(" ns")); +} + +/* Takes too long +TEST(Timer, STimes) { + CLI::Timer timer; + std::this_thread::sleep_for(std::chrono::seconds(1)); + std::string output = timer.to_string(); + EXPECT_THAT(output, HasSubstr(" s")); +} +*/ + +// Fails on Windows +// TEST(Timer, UStimes) { +// CLI::Timer timer; +// std::this_thread::sleep_for(std::chrono::microseconds(2)); +// std::string output = timer.to_string(); +// EXPECT_THAT(output, HasSubstr(" ms")); +//} + +TEST(Timer, BigTimer) { + CLI::Timer timer{"My Timer", CLI::Timer::Big}; + std::string output = timer.to_string(); + EXPECT_THAT(output, HasSubstr("Time =")); + EXPECT_THAT(output, HasSubstr("-----------")); +} + +TEST(Timer, AutoTimer) { + CLI::AutoTimer timer; + std::string output = timer.to_string(); + EXPECT_THAT(output, HasSubstr("Timer")); +} + +TEST(Timer, PrintTimer) { + std::stringstream out; + CLI::AutoTimer timer; + out << timer; + std::string output = out.str(); + EXPECT_THAT(output, HasSubstr("Timer")); +} + +TEST(Timer, TimeItTimer) { + CLI::Timer timer; + std::string output = timer.time_it([]() { std::this_thread::sleep_for(std::chrono::milliseconds(10)); }, .1); + std::cout << output << std::endl; + EXPECT_THAT(output, HasSubstr("ms")); +} diff --git a/packages/CLI11/tests/app_helper.hpp b/packages/CLI11/tests/app_helper.hpp new file mode 100644 index 0000000000000000000000000000000000000000..49ef7554abf38184549ea7ff984e365a52633702 --- /dev/null +++ b/packages/CLI11/tests/app_helper.hpp @@ -0,0 +1,56 @@ +#pragma once + +#ifdef CLI_SINGLE_FILE +#include "CLI11.hpp" +#else +#include "CLI/CLI.hpp" +#endif + +#include "gtest/gtest.h" +#include <iostream> + +typedef std::vector<std::string> input_t; + +struct TApp : public ::testing::Test { + CLI::App app{"My Test Program"}; + input_t args; + + void run() { + input_t newargs = args; + std::reverse(std::begin(newargs), std::end(newargs)); + app.parse(newargs); + } +}; + +class TempFile { + std::string _name; + + public: + TempFile(std::string name) : _name(name) { + if(!CLI::NonexistentPath(_name).empty()) + throw std::runtime_error(_name); + } + + ~TempFile() { + std::remove(_name.c_str()); // Doesn't matter if returns 0 or not + } + + operator const std::string &() const { return _name; } + const char *c_str() const { return _name.c_str(); } +}; + +inline void put_env(std::string name, std::string value) { +#ifdef _MSC_VER + _putenv_s(name.c_str(), value.c_str()); +#else + setenv(name.c_str(), value.c_str(), 1); +#endif +} + +inline void unset_env(std::string name) { +#ifdef _MSC_VER + _putenv_s(name.c_str(), ""); +#else + unsetenv(name.c_str()); +#endif +} diff --git a/packages/CLI11/tests/link_test_1.cpp b/packages/CLI11/tests/link_test_1.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6be3bfae5198c7fc0703f3fa4a5115da2abdfd0a --- /dev/null +++ b/packages/CLI11/tests/link_test_1.cpp @@ -0,0 +1,4 @@ +#include "CLI/CLI.hpp" +#include "CLI/Timer.hpp" + +int do_nothing() { return 7; } diff --git a/packages/CLI11/tests/link_test_2.cpp b/packages/CLI11/tests/link_test_2.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a198b6ed71d95c77621c474c34f16068c4ea268e --- /dev/null +++ b/packages/CLI11/tests/link_test_2.cpp @@ -0,0 +1,11 @@ +#include "CLI/CLI.hpp" +#include "CLI/Timer.hpp" +#include <gtest/gtest.h> + +int do_nothing(); + +// Verifies there are no ungarded inlines +TEST(Link, DoNothing) { + int a = do_nothing(); + EXPECT_EQ(7, a); +}