Skip to content

Commit

Permalink
Merge pull request #2139 from joto/update-cli11
Browse files Browse the repository at this point in the history
Update included CLI11 library to version 2.4.1
  • Loading branch information
lonvia authored Feb 12, 2024
2 parents 6fe04d7 + 9bcc139 commit 8b72451
Show file tree
Hide file tree
Showing 28 changed files with 1,890 additions and 491 deletions.
2 changes: 1 addition & 1 deletion contrib/CLI11/README.contrib
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Source: https://github.com/CLIUtils/CLI11
Revision: v2.3.2
Revision: v2.4.1
298 changes: 160 additions & 138 deletions contrib/CLI11/README.md

Large diffs are not rendered by default.

50 changes: 46 additions & 4 deletions contrib/CLI11/include/CLI/App.hpp
Original file line number Diff line number Diff line change
@@ -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.
//
Expand Down Expand Up @@ -35,9 +35,9 @@ namespace CLI {
// [CLI11:app_hpp:verbatim]

#ifndef CLI11_PARSE
#define CLI11_PARSE(app, argc, argv) \
#define CLI11_PARSE(app, ...) \
try { \
(app).parse((argc), (argv)); \
(app).parse(__VA_ARGS__); \
} catch(const CLI::ParseError &e) { \
return (app).exit(e); \
}
Expand Down Expand Up @@ -150,6 +150,12 @@ class App {
/// @name Help
///@{

/// Usage to put after program/subcommand description in the help output INHERITABLE
std::string usage_{};

/// This is a function that generates a usage to put after program/subcommand description in help output
std::function<std::string()> usage_callback_{};

/// Footer to put after all options in the help output INHERITABLE
std::string footer_{};

Expand Down Expand Up @@ -284,6 +290,14 @@ class App {

///@}

#ifdef _WIN32
/// When normalizing argv to UTF-8 on Windows, this is the storage for normalized args.
std::vector<std::string> normalized_argv_{};

/// When normalizing argv to UTF-8 on Windows, this is the `char**` value returned to the user.
std::vector<char *> normalized_argv_view_{};
#endif

/// Special private constructor for subcommand
App(std::string app_description, std::string app_name, App *parent);

Expand All @@ -303,6 +317,9 @@ class App {
/// virtual destructor
virtual ~App() = default;

/// Convert the contents of argv to UTF-8. Only does something on Windows, does nothing elsewhere.
CLI11_NODISCARD char **ensure_utf8(char **argv);

/// Set a callback for execution when all parsing and processing has completed
///
/// Due to a bug in c++11,
Expand Down Expand Up @@ -834,12 +851,18 @@ class App {
/// Parses the command line - throws errors.
/// This must be called after the options are in but before the rest of the program.
void parse(int argc, const char *const *argv);
void parse(int argc, const wchar_t *const *argv);

private:
template <class CharT> void parse_char_t(int argc, const CharT *const *argv);

public:
/// Parse a single string as if it contained command line arguments.
/// This function splits the string into arguments then calls parse(std::vector<std::string> &)
/// the function takes an optional boolean argument specifying if the programName is included in the string to
/// process
void parse(std::string commandline, bool program_name_included = false);
void parse(std::wstring commandline, bool program_name_included = false);

/// The real work is done here. Expects a reversed vector.
/// Changes the vector to the remaining options.
Expand Down Expand Up @@ -947,6 +970,16 @@ class App {
/// @name Help
///@{

/// Set usage.
App *usage(std::string usage_string) {
usage_ = std::move(usage_string);
return this;
}
/// Set usage.
App *usage(std::function<std::string()> usage_function) {
usage_callback_ = std::move(usage_function);
return this;
}
/// Set footer.
App *footer(std::string footer_string) {
footer_ = std::move(footer_string);
Expand Down Expand Up @@ -1055,6 +1088,11 @@ class App {
/// Get the group of this subcommand
CLI11_NODISCARD const std::string &get_group() const { return group_; }

/// Generate and return the usage.
CLI11_NODISCARD std::string get_usage() const {
return (usage_callback_) ? usage_callback_() + '\n' + usage_ : usage_;
}

/// Generate and return the footer.
CLI11_NODISCARD std::string get_footer() const {
return (footer_callback_) ? footer_callback_() + '\n' + footer_ : footer_;
Expand Down Expand Up @@ -1192,6 +1230,9 @@ class App {
/// Read and process a configuration file (main app only)
void _process_config_file();

/// Read and process a particular configuration file
bool _process_config_file(const std::string &config_file, bool throw_error);

/// Get envname options if not yet passed. Runs on *all* subcommands.
void _process_env();

Expand Down Expand Up @@ -1264,8 +1305,9 @@ class App {
bool _parse_subcommand(std::vector<std::string> &args);

/// Parse a short (false) or long (true) argument, must be at the top of the list
/// if local_processing_only is set to true then fallthrough is disabled will return false if not found
/// return true if the argument was processed or false if nothing was done
bool _parse_arg(std::vector<std::string> &args, detail::Classifier current_type);
bool _parse_arg(std::vector<std::string> &args, detail::Classifier current_type, bool local_processing_only);

/// Trigger the pre_parse callback if needed
void _trigger_pre_parse(std::size_t remaining_args);
Expand Down
29 changes: 29 additions & 0 deletions contrib/CLI11/include/CLI/Argv.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) 2017-2024, University of Cincinnati, developed by Henry Schreiner
// under NSF AWARD 1414736 and by the respective contributors.
// All rights reserved.
//
// SPDX-License-Identifier: BSD-3-Clause

#pragma once

// [CLI11:public_includes:set]
#include <string>
#include <vector>
// [CLI11:public_includes:end]

#include <CLI/Macros.hpp>

namespace CLI {
// [CLI11:argv_hpp:verbatim]
namespace detail {
#ifdef _WIN32
/// Decode and return UTF-8 argv from GetCommandLineW.
CLI11_INLINE std::vector<std::string> compute_win32_argv();
#endif
} // namespace detail
// [CLI11:argv_hpp:end]
} // namespace CLI

#ifndef CLI11_COMPILE
#include "impl/Argv_inl.hpp"
#endif
6 changes: 5 additions & 1 deletion contrib/CLI11/include/CLI/CLI.hpp
Original file line number Diff line number Diff line change
@@ -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.
//
Expand All @@ -13,6 +13,10 @@

#include "Macros.hpp"

#include "Encoding.hpp"

#include "Argv.hpp"

#include "StringTools.hpp"

#include "Error.hpp"
Expand Down
13 changes: 9 additions & 4 deletions contrib/CLI11/include/CLI/Config.hpp
Original file line number Diff line number Diff line change
@@ -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.
//
Expand All @@ -14,7 +14,7 @@
#include <string>
#include <utility>
#include <vector>
// [CLI11:public_includes:set]
// [CLI11:public_includes:end]

#include "App.hpp"
#include "ConfigFwd.hpp"
Expand All @@ -24,15 +24,20 @@ namespace CLI {
// [CLI11:config_hpp:verbatim]
namespace detail {

std::string convert_arg_for_ini(const std::string &arg, char stringQuote = '"', char characterQuote = '\'');
std::string convert_arg_for_ini(const std::string &arg,
char stringQuote = '"',
char literalQuote = '\'',
bool disable_multi_line = false);

/// Comma separated join, adds quotes if needed
std::string ini_join(const std::vector<std::string> &args,
char sepChar = ',',
char arrayStart = '[',
char arrayEnd = ']',
char stringQuote = '"',
char characterQuote = '\'');
char literalQuote = '\'');

void clean_name_string(std::string &name, const std::string &keyChars);

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

Expand Down
14 changes: 7 additions & 7 deletions contrib/CLI11/include/CLI/ConfigFwd.hpp
Original file line number Diff line number Diff line change
@@ -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.
//
Expand All @@ -10,6 +10,7 @@
#include <algorithm>
#include <fstream>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
// [CLI11:public_includes:end]
Expand All @@ -29,7 +30,6 @@ struct ConfigItem {

/// This is the name
std::string name{};

/// Listing of inputs
std::vector<std::string> inputs{};

Expand Down Expand Up @@ -92,8 +92,8 @@ class ConfigBase : public Config {
char valueDelimiter = '=';
/// the character to use around strings
char stringQuote = '"';
/// the character to use around single characters
char characterQuote = '\'';
/// the character to use around single characters and literal strings
char literalQuote = '\'';
/// the maximum number of layers to allow
uint8_t maximumLayers{255};
/// the separator used to separator parent layers
Expand Down Expand Up @@ -129,10 +129,10 @@ class ConfigBase : public Config {
valueDelimiter = vSep;
return this;
}
/// Specify the quote characters used around strings and characters
ConfigBase *quoteCharacter(char qString, char qChar) {
/// Specify the quote characters used around strings and literal strings
ConfigBase *quoteCharacter(char qString, char literalChar) {
stringQuote = qString;
characterQuote = qChar;
literalQuote = literalChar;
return this;
}
/// Specify the maximum number of parents
Expand Down
54 changes: 54 additions & 0 deletions contrib/CLI11/include/CLI/Encoding.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright (c) 2017-2024, University of Cincinnati, developed by Henry Schreiner
// under NSF AWARD 1414736 and by the respective contributors.
// All rights reserved.
//
// SPDX-License-Identifier: BSD-3-Clause

#pragma once

#include <CLI/Macros.hpp>

// [CLI11:public_includes:set]
#include <string>
// [CLI11:public_includes:end]

// [CLI11:encoding_includes:verbatim]
#ifdef CLI11_CPP17
#include <string_view>
#endif // CLI11_CPP17

#if defined CLI11_HAS_FILESYSTEM && CLI11_HAS_FILESYSTEM > 0
#include <filesystem>
#include <string_view> // NOLINT(build/include)
#endif // CLI11_HAS_FILESYSTEM
// [CLI11:encoding_includes:end]

namespace CLI {
// [CLI11:encoding_hpp:verbatim]

/// Convert a wide string to a narrow string.
CLI11_INLINE std::string narrow(const std::wstring &str);
CLI11_INLINE std::string narrow(const wchar_t *str);
CLI11_INLINE std::string narrow(const wchar_t *str, std::size_t size);

/// Convert a narrow string to a wide string.
CLI11_INLINE std::wstring widen(const std::string &str);
CLI11_INLINE std::wstring widen(const char *str);
CLI11_INLINE std::wstring widen(const char *str, std::size_t size);

#ifdef CLI11_CPP17
CLI11_INLINE std::string narrow(std::wstring_view str);
CLI11_INLINE std::wstring widen(std::string_view str);
#endif // CLI11_CPP17

#if defined CLI11_HAS_FILESYSTEM && CLI11_HAS_FILESYSTEM > 0
/// Convert a char-string to a native path correctly.
CLI11_INLINE std::filesystem::path to_path(std::string_view str);
#endif // CLI11_HAS_FILESYSTEM

// [CLI11:encoding_hpp:end]
} // namespace CLI

#ifndef CLI11_COMPILE
#include "impl/Encoding_inl.hpp"
#endif
8 changes: 7 additions & 1 deletion contrib/CLI11/include/CLI/Error.hpp
Original file line number Diff line number Diff line change
@@ -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.
//
Expand Down Expand Up @@ -123,7 +123,13 @@ class BadNameString : public ConstructionError {
CLI11_ERROR_DEF(ConstructionError, BadNameString)
CLI11_ERROR_SIMPLE(BadNameString)
static BadNameString OneCharName(std::string name) { return BadNameString("Invalid one char name: " + name); }
static BadNameString MissingDash(std::string name) {
return BadNameString("Long names strings require 2 dashes " + name);
}
static BadNameString BadLongName(std::string name) { return BadNameString("Bad long name: " + name); }
static BadNameString BadPositionalName(std::string name) {
return BadNameString("Invalid positional Name: " + name);
}
static BadNameString DashesOnly(std::string name) {
return BadNameString("Must have a name, not just dashes: " + name);
}
Expand Down
2 changes: 1 addition & 1 deletion contrib/CLI11/include/CLI/Formatter.hpp
Original file line number Diff line number Diff line change
@@ -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.
//
Expand Down
2 changes: 1 addition & 1 deletion contrib/CLI11/include/CLI/FormatterFwd.hpp
Original file line number Diff line number Diff line change
@@ -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.
//
Expand Down
Loading

0 comments on commit 8b72451

Please sign in to comment.