1- // Copyright (c) 2017-2023 , University of Cincinnati, developed by Henry Schreiner
1+ // Copyright (c) 2017-2024 , University of Cincinnati, developed by Henry Schreiner
22// under NSF AWARD 1414736 and by the respective contributors.
33// All rights reserved.
44//
@@ -35,9 +35,9 @@ namespace CLI {
3535// [CLI11:app_hpp:verbatim]
3636
3737#ifndef CLI11_PARSE
38- #define CLI11_PARSE (app, argc, argv ) \
38+ #define CLI11_PARSE (app, ...) \
3939 try { \
40- (app).parse ((argc), (argv)); \
40+ (app).parse (__VA_ARGS__); \
4141 } catch (const CLI::ParseError &e) { \
4242 return (app).exit (e); \
4343 }
@@ -150,6 +150,12 @@ class App {
150150 // / @name Help
151151 // /@{
152152
153+ // / Usage to put after program/subcommand description in the help output INHERITABLE
154+ std::string usage_{};
155+
156+ // / This is a function that generates a usage to put after program/subcommand description in help output
157+ std::function<std::string()> usage_callback_{};
158+
153159 // / Footer to put after all options in the help output INHERITABLE
154160 std::string footer_{};
155161
@@ -284,6 +290,14 @@ class App {
284290
285291 // /@}
286292
293+ #ifdef _WIN32
294+ // / When normalizing argv to UTF-8 on Windows, this is the storage for normalized args.
295+ std::vector<std::string> normalized_argv_{};
296+
297+ // / When normalizing argv to UTF-8 on Windows, this is the `char**` value returned to the user.
298+ std::vector<char *> normalized_argv_view_{};
299+ #endif
300+
287301 // / Special private constructor for subcommand
288302 App (std::string app_description, std::string app_name, App *parent);
289303
@@ -303,6 +317,9 @@ class App {
303317 // / virtual destructor
304318 virtual ~App () = default ;
305319
320+ // / Convert the contents of argv to UTF-8. Only does something on Windows, does nothing elsewhere.
321+ CLI11_NODISCARD char **ensure_utf8 (char **argv);
322+
306323 // / Set a callback for execution when all parsing and processing has completed
307324 // /
308325 // / Due to a bug in c++11,
@@ -834,12 +851,18 @@ class App {
834851 // / Parses the command line - throws errors.
835852 // / This must be called after the options are in but before the rest of the program.
836853 void parse (int argc, const char *const *argv);
854+ void parse (int argc, const wchar_t *const *argv);
855+
856+ private:
857+ template <class CharT > void parse_char_t (int argc, const CharT *const *argv);
837858
859+ public:
838860 // / Parse a single string as if it contained command line arguments.
839861 // / This function splits the string into arguments then calls parse(std::vector<std::string> &)
840862 // / the function takes an optional boolean argument specifying if the programName is included in the string to
841863 // / process
842864 void parse (std::string commandline, bool program_name_included = false );
865+ void parse (std::wstring commandline, bool program_name_included = false );
843866
844867 // / The real work is done here. Expects a reversed vector.
845868 // / Changes the vector to the remaining options.
@@ -947,6 +970,16 @@ class App {
947970 // / @name Help
948971 // /@{
949972
973+ // / Set usage.
974+ App *usage (std::string usage_string) {
975+ usage_ = std::move (usage_string);
976+ return this ;
977+ }
978+ // / Set usage.
979+ App *usage (std::function<std::string()> usage_function) {
980+ usage_callback_ = std::move (usage_function);
981+ return this ;
982+ }
950983 // / Set footer.
951984 App *footer (std::string footer_string) {
952985 footer_ = std::move (footer_string);
@@ -1055,6 +1088,11 @@ class App {
10551088 // / Get the group of this subcommand
10561089 CLI11_NODISCARD const std::string &get_group () const { return group_; }
10571090
1091+ // / Generate and return the usage.
1092+ CLI11_NODISCARD std::string get_usage () const {
1093+ return (usage_callback_) ? usage_callback_ () + ' \n ' + usage_ : usage_;
1094+ }
1095+
10581096 // / Generate and return the footer.
10591097 CLI11_NODISCARD std::string get_footer () const {
10601098 return (footer_callback_) ? footer_callback_ () + ' \n ' + footer_ : footer_;
@@ -1192,6 +1230,9 @@ class App {
11921230 // / Read and process a configuration file (main app only)
11931231 void _process_config_file ();
11941232
1233+ // / Read and process a particular configuration file
1234+ bool _process_config_file (const std::string &config_file, bool throw_error);
1235+
11951236 // / Get envname options if not yet passed. Runs on *all* subcommands.
11961237 void _process_env ();
11971238
@@ -1264,8 +1305,9 @@ class App {
12641305 bool _parse_subcommand (std::vector<std::string> &args);
12651306
12661307 // / Parse a short (false) or long (true) argument, must be at the top of the list
1308+ // / if local_processing_only is set to true then fallthrough is disabled will return false if not found
12671309 // / return true if the argument was processed or false if nothing was done
1268- bool _parse_arg (std::vector<std::string> &args, detail::Classifier current_type);
1310+ bool _parse_arg (std::vector<std::string> &args, detail::Classifier current_type, bool local_processing_only );
12691311
12701312 // / Trigger the pre_parse callback if needed
12711313 void _trigger_pre_parse (std::size_t remaining_args);
0 commit comments