diff --git a/book/chapters/config.md b/book/chapters/config.md index 8a726102e..8991bf9ee 100644 --- a/book/chapters/config.md +++ b/book/chapters/config.md @@ -323,6 +323,10 @@ char literalQuote = '\''; uint8_t maximumLayers{255}; /// the separator used to separator parent layers char parentSeparatorChar{'.'}; +/// comment default values +bool commentDefaultsBool = false; +/// specify the config reader should collapse repeated field names to a single vector +bool allowMultipleDuplicateFields{false}; /// Specify the configuration index to use for arrayed sections uint16_t configIndex{0}; /// Specify the configuration section that should be used @@ -341,6 +345,10 @@ These can be modified via setter functions and value - `ConfigBase *quoteCharacter(char qString, char literalChar)` :specify the characters to use around strings and single characters +- `ConfigBase *commentDefaults(bool comDef)` : set to true to comment lines with + a default value +- `ConfigBase *allowDuplicateFields(bool value)` :set to true to allow duplicate + fields to be merged even if not sequential - `ConfigBase *maxLayers(uint8_t layers)` : specify the maximum number of parent layers to process. This is useful to limit processing for larger config files - `ConfigBase *parentSeparator(char sep)` : specify the character to separate @@ -450,8 +458,8 @@ positional, or the environment variable name. When generating a config file it will create an option name in following priority. 1. First long name -2. Positional name -3. First short name +2. First short name +3. Positional name 4. Environment name In config files the name will be enclosed in quotes if there is any potential diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 24a5be64a..1173d6b6e 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -251,6 +251,11 @@ add_cli_exe(custom_parse custom_parse.cpp) add_test(NAME cp_test COMMAND custom_parse --dv 1.7) set_property(TEST cp_test PROPERTY PASS_REGULAR_EXPRESSION "called correct") +#----------------------------------------------------- +add_cli_exe(help_usage help_usage.cpp) +add_test(NAME help_use COMMAND help_usage --help) +set_property(TEST help_use PROPERTY PASS_REGULAR_EXPRESSION "[1..9]") + #------------------------------------------------ # This executable is for manual testing and is expected to change regularly diff --git a/examples/help_usage.cpp b/examples/help_usage.cpp index 6b7d19011..d747cb3cf 100644 --- a/examples/help_usage.cpp +++ b/examples/help_usage.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2023, University of Cincinnati, developed by Henry Schreiner +// Copyright (c) 2017-2024, University of Cincinnati, developed by Henry Schreiner // under NSF AWARD 1414736 and by the respective contributors. // All rights reserved. // @@ -9,7 +9,7 @@ int main(int argc, char **argv) { std::string input_file_name, output_file_name; - int level, subopt; + int level{5}, subopt{0}; // app caption CLI::App app{"CLI11 help"}; @@ -47,26 +47,29 @@ int main(int argc, char **argv) { /* $ ./help_usage -h -CLI11 help -Usage: help_usage [options] + CLI11 help -Options: - -h,--help +OPTIONS: + -h, --help -Subcommands: +SUBCOMMANDS: e encode - Positionals: - input input file - output output file - Options: - -l,--level [1..9] encoding level - -K,--remove INT remove input file - -s,--suboption suboption + +POSITIONALS: + input input file + output output file + +OPTIONS: + -l, --level [1..9] encoding level + -R, --remove remove input file + -s, --suboption suboption + d decode - Positionals: - input input file - output output file + +POSITIONALS: + input input file + output output file */ diff --git a/include/CLI/ConfigFwd.hpp b/include/CLI/ConfigFwd.hpp index 3f8ffdb7f..ef1c83d9e 100644 --- a/include/CLI/ConfigFwd.hpp +++ b/include/CLI/ConfigFwd.hpp @@ -102,10 +102,12 @@ class ConfigBase : public Config { uint8_t maximumLayers{255}; /// the separator used to separator parent layers char parentSeparatorChar{'.'}; - /// Specify the configuration index to use for arrayed sections - int16_t configIndex{-1}; + /// comment default values + bool commentDefaultsBool = false; /// specify the config reader should collapse repeated field names to a single vector bool allowMultipleDuplicateFields{false}; + /// Specify the configuration index to use for arrayed sections + int16_t configIndex{-1}; /// Specify the configuration section that should be used std::string configSection{}; @@ -151,6 +153,11 @@ class ConfigBase : public Config { parentSeparatorChar = sep; return this; } + /// comment default value options + ConfigBase *commentDefaults(bool comDef = true) { + commentDefaultsBool = comDef; + return this; + } /// get a reference to the configuration section std::string §ionRef() { return configSection; } /// get the section diff --git a/include/CLI/Option.hpp b/include/CLI/Option.hpp index f6f848aa7..24acc82d3 100644 --- a/include/CLI/Option.hpp +++ b/include/CLI/Option.hpp @@ -547,7 +547,7 @@ class Option : public OptionBase