Skip to content

Commit 8b72451

Browse files
authored
Merge pull request #2139 from joto/update-cli11
Update included CLI11 library to version 2.4.1
2 parents 6fe04d7 + 9bcc139 commit 8b72451

28 files changed

+1890
-491
lines changed

contrib/CLI11/README.contrib

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
Source: https://github.com/CLIUtils/CLI11
2-
Revision: v2.3.2
2+
Revision: v2.4.1

contrib/CLI11/README.md

Lines changed: 160 additions & 138 deletions
Large diffs are not rendered by default.

contrib/CLI11/include/CLI/App.hpp

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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);

contrib/CLI11/include/CLI/Argv.hpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright (c) 2017-2024, University of Cincinnati, developed by Henry Schreiner
2+
// under NSF AWARD 1414736 and by the respective contributors.
3+
// All rights reserved.
4+
//
5+
// SPDX-License-Identifier: BSD-3-Clause
6+
7+
#pragma once
8+
9+
// [CLI11:public_includes:set]
10+
#include <string>
11+
#include <vector>
12+
// [CLI11:public_includes:end]
13+
14+
#include <CLI/Macros.hpp>
15+
16+
namespace CLI {
17+
// [CLI11:argv_hpp:verbatim]
18+
namespace detail {
19+
#ifdef _WIN32
20+
/// Decode and return UTF-8 argv from GetCommandLineW.
21+
CLI11_INLINE std::vector<std::string> compute_win32_argv();
22+
#endif
23+
} // namespace detail
24+
// [CLI11:argv_hpp:end]
25+
} // namespace CLI
26+
27+
#ifndef CLI11_COMPILE
28+
#include "impl/Argv_inl.hpp"
29+
#endif

contrib/CLI11/include/CLI/CLI.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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
//
@@ -13,6 +13,10 @@
1313

1414
#include "Macros.hpp"
1515

16+
#include "Encoding.hpp"
17+
18+
#include "Argv.hpp"
19+
1620
#include "StringTools.hpp"
1721

1822
#include "Error.hpp"

contrib/CLI11/include/CLI/Config.hpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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
//
@@ -14,7 +14,7 @@
1414
#include <string>
1515
#include <utility>
1616
#include <vector>
17-
// [CLI11:public_includes:set]
17+
// [CLI11:public_includes:end]
1818

1919
#include "App.hpp"
2020
#include "ConfigFwd.hpp"
@@ -24,15 +24,20 @@ namespace CLI {
2424
// [CLI11:config_hpp:verbatim]
2525
namespace detail {
2626

27-
std::string convert_arg_for_ini(const std::string &arg, char stringQuote = '"', char characterQuote = '\'');
27+
std::string convert_arg_for_ini(const std::string &arg,
28+
char stringQuote = '"',
29+
char literalQuote = '\'',
30+
bool disable_multi_line = false);
2831

2932
/// Comma separated join, adds quotes if needed
3033
std::string ini_join(const std::vector<std::string> &args,
3134
char sepChar = ',',
3235
char arrayStart = '[',
3336
char arrayEnd = ']',
3437
char stringQuote = '"',
35-
char characterQuote = '\'');
38+
char literalQuote = '\'');
39+
40+
void clean_name_string(std::string &name, const std::string &keyChars);
3641

3742
std::vector<std::string> generate_parents(const std::string &section, std::string &name, char parentSeparator);
3843

contrib/CLI11/include/CLI/ConfigFwd.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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
//
@@ -10,6 +10,7 @@
1010
#include <algorithm>
1111
#include <fstream>
1212
#include <iostream>
13+
#include <memory>
1314
#include <string>
1415
#include <vector>
1516
// [CLI11:public_includes:end]
@@ -29,7 +30,6 @@ struct ConfigItem {
2930

3031
/// This is the name
3132
std::string name{};
32-
3333
/// Listing of inputs
3434
std::vector<std::string> inputs{};
3535

@@ -92,8 +92,8 @@ class ConfigBase : public Config {
9292
char valueDelimiter = '=';
9393
/// the character to use around strings
9494
char stringQuote = '"';
95-
/// the character to use around single characters
96-
char characterQuote = '\'';
95+
/// the character to use around single characters and literal strings
96+
char literalQuote = '\'';
9797
/// the maximum number of layers to allow
9898
uint8_t maximumLayers{255};
9999
/// the separator used to separator parent layers
@@ -129,10 +129,10 @@ class ConfigBase : public Config {
129129
valueDelimiter = vSep;
130130
return this;
131131
}
132-
/// Specify the quote characters used around strings and characters
133-
ConfigBase *quoteCharacter(char qString, char qChar) {
132+
/// Specify the quote characters used around strings and literal strings
133+
ConfigBase *quoteCharacter(char qString, char literalChar) {
134134
stringQuote = qString;
135-
characterQuote = qChar;
135+
literalQuote = literalChar;
136136
return this;
137137
}
138138
/// Specify the maximum number of parents
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright (c) 2017-2024, University of Cincinnati, developed by Henry Schreiner
2+
// under NSF AWARD 1414736 and by the respective contributors.
3+
// All rights reserved.
4+
//
5+
// SPDX-License-Identifier: BSD-3-Clause
6+
7+
#pragma once
8+
9+
#include <CLI/Macros.hpp>
10+
11+
// [CLI11:public_includes:set]
12+
#include <string>
13+
// [CLI11:public_includes:end]
14+
15+
// [CLI11:encoding_includes:verbatim]
16+
#ifdef CLI11_CPP17
17+
#include <string_view>
18+
#endif // CLI11_CPP17
19+
20+
#if defined CLI11_HAS_FILESYSTEM && CLI11_HAS_FILESYSTEM > 0
21+
#include <filesystem>
22+
#include <string_view> // NOLINT(build/include)
23+
#endif // CLI11_HAS_FILESYSTEM
24+
// [CLI11:encoding_includes:end]
25+
26+
namespace CLI {
27+
// [CLI11:encoding_hpp:verbatim]
28+
29+
/// Convert a wide string to a narrow string.
30+
CLI11_INLINE std::string narrow(const std::wstring &str);
31+
CLI11_INLINE std::string narrow(const wchar_t *str);
32+
CLI11_INLINE std::string narrow(const wchar_t *str, std::size_t size);
33+
34+
/// Convert a narrow string to a wide string.
35+
CLI11_INLINE std::wstring widen(const std::string &str);
36+
CLI11_INLINE std::wstring widen(const char *str);
37+
CLI11_INLINE std::wstring widen(const char *str, std::size_t size);
38+
39+
#ifdef CLI11_CPP17
40+
CLI11_INLINE std::string narrow(std::wstring_view str);
41+
CLI11_INLINE std::wstring widen(std::string_view str);
42+
#endif // CLI11_CPP17
43+
44+
#if defined CLI11_HAS_FILESYSTEM && CLI11_HAS_FILESYSTEM > 0
45+
/// Convert a char-string to a native path correctly.
46+
CLI11_INLINE std::filesystem::path to_path(std::string_view str);
47+
#endif // CLI11_HAS_FILESYSTEM
48+
49+
// [CLI11:encoding_hpp:end]
50+
} // namespace CLI
51+
52+
#ifndef CLI11_COMPILE
53+
#include "impl/Encoding_inl.hpp"
54+
#endif

contrib/CLI11/include/CLI/Error.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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
//
@@ -123,7 +123,13 @@ class BadNameString : public ConstructionError {
123123
CLI11_ERROR_DEF(ConstructionError, BadNameString)
124124
CLI11_ERROR_SIMPLE(BadNameString)
125125
static BadNameString OneCharName(std::string name) { return BadNameString("Invalid one char name: " + name); }
126+
static BadNameString MissingDash(std::string name) {
127+
return BadNameString("Long names strings require 2 dashes " + name);
128+
}
126129
static BadNameString BadLongName(std::string name) { return BadNameString("Bad long name: " + name); }
130+
static BadNameString BadPositionalName(std::string name) {
131+
return BadNameString("Invalid positional Name: " + name);
132+
}
127133
static BadNameString DashesOnly(std::string name) {
128134
return BadNameString("Must have a name, not just dashes: " + name);
129135
}

contrib/CLI11/include/CLI/Formatter.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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
//

0 commit comments

Comments
 (0)