From 2baa0498db3c747e00e15a346ecbf3fef3c77da1 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 4 Jan 2024 14:50:26 +0000 Subject: [PATCH] style: pre-commit.ci fixes --- README.md | 25 ++++++++++----- include/CLI/Validators.hpp | 4 +-- include/CLI/impl/Config_inl.hpp | 4 +-- include/CLI/impl/Validators_inl.hpp | 24 +++++--------- tests/OptionTypeTest.cpp | 2 +- tests/TransformTest.cpp | 50 ++++++++++++++--------------- 6 files changed, 53 insertions(+), 56 deletions(-) diff --git a/README.md b/README.md index c2bc2e036..4c454d409 100644 --- a/README.md +++ b/README.md @@ -702,7 +702,12 @@ filters on the key values is performed. `CLI::FileOnDefaultPath(default_path, false)`. This allows multiple paths to be chained using multiple transform calls. -- `CLI::EscapedString`: 🚧 can be used to process an escaped string. The processing is equivalent to that used for TOML config files, see [TOML strings](https://toml.io/en/v1.0.0#string). With 2 notable exceptions. `\`` can also be used as a literal string notation, and it also allows binary string notation see [binary strings](TO ADD). The escaped string processing will remove outer quotes if present, `"` will indicate a string with potential escape sequences, `'` and `\`` will indicate a literal string and the quotes removed but no escape sequences will be processed. This is the same escape processing as used in config files. +- `CLI::EscapedString`: 🚧 can be used to process an escaped string. The + processing is equivalent to that used for TOML config files, see + [TOML strings](https://toml.io/en/v1.0.0#string). With 2 notable exceptions. + `\`` can also be used as a literal string notation, and it also allows binary string notation see [binary strings](TO ADD). The escaped string processing will remove outer quotes if present, `"`will indicate a string with potential escape sequences, `'`and`\`` + will indicate a literal string and the quotes removed but no escape sequences + will be processed. This is the same escape processing as used in config files. ##### Validator operations @@ -875,9 +880,11 @@ through the `add_subcommand` method have the same restrictions as option names. - `--subcommand1.subsub.f val` (short form nested subcommand option) The use of dot notation in this form is equivalent `--subcommand.long ` => -`subcommand --long ++`. Nested subcommands also work `sub1.subsub` -would trigger the subsub subcommand in `sub1`. This is equivalent to "sub1 -subsub". Quotes around the subcommand names are permitted 🚧 following the TOML standard for such specification. This includes allowing escape sequences. For example `"subcommand".'f'` or `"subcommand.with.dots".arg1 = value`. +`subcommand --long ++`. Nested subcommands also work `sub1.subsub` would +trigger the subsub subcommand in `sub1`. This is equivalent to "sub1 subsub". +Quotes around the subcommand names are permitted 🚧 following the TOML standard +for such specification. This includes allowing escape sequences. For example +`"subcommand".'f'` or `"subcommand.with.dots".arg1 = value`. #### Subcommand options @@ -1211,10 +1218,12 @@ 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 [TOML][] format by default, though the -default reader can also accept files in INI format as well. The config reader can read most aspects of TOML files including strings both literal 🚧 and with potential escape sequences 🚧, digit separators 🚧, and multi-line strings 🚧, and run them through the CLI11 -parser. Other formats can be added by an adept user, some variations are -available through customization points in the default formatter. An example of a -TOML file: +default reader can also accept files in INI format as well. The config reader +can read most aspects of TOML files including strings both literal 🚧 and with +potential escape sequences 🚧, digit separators 🚧, and multi-line strings 🚧, +and run them through the CLI11 parser. Other formats can be added by an adept +user, some variations are available through customization points in the default +formatter. An example of a TOML file: ```toml # Comments are supported, using a # diff --git a/include/CLI/Validators.hpp b/include/CLI/Validators.hpp index d52eaf9d6..7c1fe5b76 100644 --- a/include/CLI/Validators.hpp +++ b/include/CLI/Validators.hpp @@ -218,8 +218,8 @@ class IPV4Validator : public Validator { IPV4Validator(); }; -class EscapedStringTransformer :public Validator { -public: +class EscapedStringTransformer : public Validator { + public: EscapedStringTransformer(); }; diff --git a/include/CLI/impl/Config_inl.hpp b/include/CLI/impl/Config_inl.hpp index b4535c792..8c4ffe24c 100644 --- a/include/CLI/impl/Config_inl.hpp +++ b/include/CLI/impl/Config_inl.hpp @@ -341,9 +341,7 @@ inline std::vector ConfigBase::from_config(std::istream &input) cons if(keyChar == '\"') { try { item = detail::remove_escaped_characters(item); - } - catch (const std::invalid_argument& ia) - { + } catch(const std::invalid_argument &ia) { throw CLI::ParseError(ia.what(), CLI::ExitCodes::InvalidError); } } diff --git a/include/CLI/impl/Validators_inl.hpp b/include/CLI/impl/Validators_inl.hpp index 145315a75..b5b95f631 100644 --- a/include/CLI/impl/Validators_inl.hpp +++ b/include/CLI/impl/Validators_inl.hpp @@ -233,29 +233,21 @@ CLI11_INLINE IPV4Validator::IPV4Validator() : Validator("IPV4") { }; } -CLI11_INLINE EscapedStringTransformer::EscapedStringTransformer() -{ +CLI11_INLINE EscapedStringTransformer::EscapedStringTransformer() { func_ = [](std::string &str) { try { - if (str.size()>1 && (str.front() == '\"' || str.front() == '\'' || str.front() == '`') &&str.front()==str.back()) - { + if(str.size() > 1 && (str.front() == '\"' || str.front() == '\'' || str.front() == '`') && + str.front() == str.back()) { process_quoted_string(str); - } - else if (str.find_first_of('\\') != std::string::npos) - { - if (detail::is_binary_escaped_string(str)) - { - str=detail::extract_binary_string(str); - } - else - { + } else if(str.find_first_of('\\') != std::string::npos) { + if(detail::is_binary_escaped_string(str)) { + str = detail::extract_binary_string(str); + } else { str = remove_escaped_characters(str); } } return std::string{}; - } - catch (const std::invalid_argument& ia) - { + } catch(const std::invalid_argument &ia) { return std::string(ia.what()); } }; diff --git a/tests/OptionTypeTest.cpp b/tests/OptionTypeTest.cpp index 8cd46500f..6bac4b8c6 100644 --- a/tests/OptionTypeTest.cpp +++ b/tests/OptionTypeTest.cpp @@ -605,7 +605,7 @@ TEST_CASE_METHOD(TApp, "IntegerOverFlowInt", "[optiontype]") { args = {"-a", "262625424225252"}; CHECK_THROWS_AS(run(), CLI::ConversionError); - + args = {"-b", "262625424225252"}; CHECK_THROWS_AS(run(), CLI::ConversionError); diff --git a/tests/TransformTest.cpp b/tests/TransformTest.cpp index cd036e2b9..b3b2bcd03 100644 --- a/tests/TransformTest.cpp +++ b/tests/TransformTest.cpp @@ -706,21 +706,20 @@ TEST_CASE_METHOD(TApp, "NumberWithUnitBadInput", "[transform]") { CHECK_THROWS_AS(run(), CLI::ValidationError); } -static const std::map validValues = -{ {"test\\u03C0\\u00e9",from_u8string(u8"test\u03C0\u00E9")}, -{"test\\u03C0\\u00e9",from_u8string(u8"test\u73C0\u0057")}, -{"test\\U0001F600\\u00E9",from_u8string(u8"test\U0001F600\u00E9")}, - {R"("this\nis\na\nfour\tline test")","this\nis\na\nfour\tline test"}, - {"'B\"(\\x35\\xa7\\x46)\"'",std::string{0x35,static_cast(0xa7),0x46} }, - {"B\"(\\x35\\xa7\\x46)\"",std::string{0x35,static_cast(0xa7),0x46} }, - {"test\\ntest","test\ntest"}, - {"\"test\\ntest","\"test\ntest"}, - {R"('this\nis\na\nfour\tline test')",R"(this\nis\na\nfour\tline test)"}, - {R"("this\nis\na\nfour\tline test")","this\nis\na\nfour\tline test"}, - {R"(`this\nis\na\nfour\tline test`)",R"(this\nis\na\nfour\tline test)"} -}; - -TEST_CASE_METHOD(TApp,"StringEscapeValid", "[transform]") { +static const std::map validValues = { + {"test\\u03C0\\u00e9", from_u8string(u8"test\u03C0\u00E9")}, + {"test\\u03C0\\u00e9", from_u8string(u8"test\u73C0\u0057")}, + {"test\\U0001F600\\u00E9", from_u8string(u8"test\U0001F600\u00E9")}, + {R"("this\nis\na\nfour\tline test")", "this\nis\na\nfour\tline test"}, + {"'B\"(\\x35\\xa7\\x46)\"'", std::string{0x35, static_cast(0xa7), 0x46}}, + {"B\"(\\x35\\xa7\\x46)\"", std::string{0x35, static_cast(0xa7), 0x46}}, + {"test\\ntest", "test\ntest"}, + {"\"test\\ntest", "\"test\ntest"}, + {R"('this\nis\na\nfour\tline test')", R"(this\nis\na\nfour\tline test)"}, + {R"("this\nis\na\nfour\tline test")", "this\nis\na\nfour\tline test"}, + {R"(`this\nis\na\nfour\tline test`)", R"(this\nis\na\nfour\tline test)"}}; + +TEST_CASE_METHOD(TApp, "StringEscapeValid", "[transform]") { auto test_data = GENERATE(from_range(validValues)); @@ -728,19 +727,20 @@ TEST_CASE_METHOD(TApp,"StringEscapeValid", "[transform]") { app.add_option("-n", value)->transform(CLI::EscapedString); - args={"-n",test_data.first}; + args = {"-n", test_data.first}; run(); CHECK(test_data.second == value); - } -static const std::vector invalidValues = -{ "test\\U0001M600\\u00E9","test\\U0001E600\\u00M9","test\\U0001E600\\uD8E9", -"test\\U0001E600\\uD8","test\\U0001E60" "test\\qbad"}; +static const std::vector invalidValues = {"test\\U0001M600\\u00E9", + "test\\U0001E600\\u00M9", + "test\\U0001E600\\uD8E9", + "test\\U0001E600\\uD8", + "test\\U0001E60" + "test\\qbad"}; - -TEST_CASE_METHOD(TApp,"StringEscapeInvalid", "[transform]") { +TEST_CASE_METHOD(TApp, "StringEscapeInvalid", "[transform]") { auto test_data = GENERATE(from_range(invalidValues)); @@ -748,13 +748,11 @@ TEST_CASE_METHOD(TApp,"StringEscapeInvalid", "[transform]") { app.add_option("-n", value)->transform(CLI::EscapedString); - args={"-n",test_data}; + args = {"-n", test_data}; - CHECK_THROWS_AS(run(),CLI::ValidationError); - + CHECK_THROWS_AS(run(), CLI::ValidationError); } - TEST_CASE_METHOD(TApp, "NumberWithUnitIntOverflow", "[transform]") { std::map mapping{{"a", 1000000}, {"b", 100}, {"c", 101}};