From e2af2db73f1bf480f3b22502a2e5591f0c066adc Mon Sep 17 00:00:00 2001 From: Philip Top Date: Thu, 11 Jan 2024 12:12:30 -0800 Subject: [PATCH 1/2] rename the `parse()` method and adjust documentation --- README.md | 23 ++++++++++++----------- include/CLI/App.hpp | 5 +++-- include/CLI/impl/App_inl.hpp | 2 +- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 41d93db38..9c3735701 100644 --- a/README.md +++ b/README.md @@ -196,7 +196,6 @@ this: ```cpp int main(int argc, char** argv) { CLI::App app{"App description"}; - argv = app.ensure_utf8(argv); std::string filename = "default"; app.add_option("-f,--file", filename, "A help string"); @@ -206,9 +205,8 @@ int main(int argc, char** argv) { } ``` -For more information about 🚧`ensure_utf8` the section on -[Unicode support](#unicode-support) below. The 🚧`ensure_utf8` function is only -available in main currently and not in a release. +For more information about unicode and operations with CLI11 see +[Unicode support](#unicode-support) below.
Note: If you don't like macros, this is what that macro expands to: (click to expand)

@@ -1411,9 +1409,9 @@ app.add_option("--fancy-count", [](std::vector val){ }); ``` -### Unicode support +### Unicode support -CLI11 supports Unicode and wide strings as defined in the +🆕 CLI11 supports Unicode and wide strings as defined in the [UTF-8 Everywhere](http://utf8everywhere.org/) manifesto. In particular: - The library can parse a wide version of command-line arguments on Windows, @@ -1445,10 +1443,9 @@ int main(int argc, char** argv) { } ``` -2\. If you pass unmodified command-line arguments to CLI11, call `app.parse()` -instead of `app.parse(argc, argv)` (or `CLI11_PARSE(app)` instead of -`CLI11_PARSE(app, argc, argv)`). The library will find correct arguments by -itself. +2\. If you pass unmodified command-line arguments to CLI11, call `app.parse_from_cli_args()` +instead of `app.parse(argc, argv)`. The library will find correct arguments by +itself, through OS calls and operations. > [!NOTE] > @@ -1460,7 +1457,11 @@ itself. > int main() { > CLI::App app; > // ... -> CLI11_PARSE(app); +> try{ +> app.parse_from_cli_args(); +> catch (const CLI::ParseError &e) { +> return app.exit(e); +> } > } > ``` diff --git a/include/CLI/App.hpp b/include/CLI/App.hpp index b63be47e7..eedf28edd 100644 --- a/include/CLI/App.hpp +++ b/include/CLI/App.hpp @@ -849,8 +849,9 @@ class App { void clear(); /// Parse the command-line arguments passed to the main function of the executable. - /// This overload will correctly parse unicode arguments on Windows. - void parse(); + /// This method will extract the arguments given to the main from the command line and parse them + /// It will correctly support unicode wide string arguments on Windows + void parse_from_cli_args(); /// Parses the command line - throws errors. /// This must be called after the options are in but before the rest of the program. diff --git a/include/CLI/impl/App_inl.hpp b/include/CLI/impl/App_inl.hpp index ae8b5f339..97426d1ce 100644 --- a/include/CLI/impl/App_inl.hpp +++ b/include/CLI/impl/App_inl.hpp @@ -529,7 +529,7 @@ CLI11_INLINE void App::clear() { } } -CLI11_INLINE void App::parse() { parse(argc(), argv()); } // LCOV_EXCL_LINE +CLI11_INLINE void App::parse_from_cli_args() { parse(argc(), argv()); } // LCOV_EXCL_LINE CLI11_INLINE void App::parse(int argc, const char *const *argv) { parse_char_t(argc, argv); } CLI11_INLINE void App::parse(int argc, const wchar_t *const *argv) { parse_char_t(argc, argv); } From 45865439c97665e7625f23f66cdc7da55c0720ce Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 11 Jan 2024 20:15:05 +0000 Subject: [PATCH 2/2] style: pre-commit.ci fixes --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 9c3735701..b1fbc49b0 100644 --- a/README.md +++ b/README.md @@ -1409,7 +1409,7 @@ app.add_option("--fancy-count", [](std::vector val){ }); ``` -### Unicode support +### Unicode support 🆕 CLI11 supports Unicode and wide strings as defined in the [UTF-8 Everywhere](http://utf8everywhere.org/) manifesto. In particular: @@ -1443,9 +1443,9 @@ int main(int argc, char** argv) { } ``` -2\. If you pass unmodified command-line arguments to CLI11, call `app.parse_from_cli_args()` -instead of `app.parse(argc, argv)`. The library will find correct arguments by -itself, through OS calls and operations. +2\. If you pass unmodified command-line arguments to CLI11, call +`app.parse_from_cli_args()` instead of `app.parse(argc, argv)`. The library will +find correct arguments by itself, through OS calls and operations. > [!NOTE] >