1
0
mirror of https://github.com/CLIUtils/CLI11.git synced 2025-05-01 13:13:53 +00:00

A few warning fixes

This commit is contained in:
Henry Fredrick Schreiner 2017-11-22 22:23:09 -05:00 committed by Henry Schreiner
parent 1286a1226e
commit c6fd8f4d83
2 changed files with 11 additions and 9 deletions

View File

@ -1511,13 +1511,13 @@ inline std::string simple(const App *app, const Error &e) {
if(app->get_help_ptr() != nullptr) if(app->get_help_ptr() != nullptr)
header += "Run with " + app->get_help_ptr()->single_name() + " for more information.\n"; header += "Run with " + app->get_help_ptr()->single_name() + " for more information.\n";
return header; return header;
}; }
inline std::string help(const App *app, const Error &e) { inline std::string help(const App *app, const Error &e) {
std::string header = std::string("ERROR: ") + e.get_name() + ": " + e.what() + "\n"; std::string header = std::string("ERROR: ") + e.get_name() + ": " + e.what() + "\n";
header += app->help(); header += app->help();
return header; return header;
}; }
} // namespace FailureMessage } // namespace FailureMessage

View File

@ -6,23 +6,25 @@
#include <exception> #include <exception>
#include <stdexcept> #include <stdexcept>
#include <string> #include <string>
#include <utility>
namespace CLI {
// Use one of these on all error classes // Use one of these on all error classes
#define CLI11_ERROR_DEF(parent, name) \ #define CLI11_ERROR_DEF(parent, name) \
protected: \ protected: \
name(std::string name, std::string msg, int exit_code) : parent(name, msg, exit_code) {} \ name(std::string name, std::string msg, int exit_code) : parent(std::move(name), std::move(msg), exit_code) {} \
name(std::string name, std::string msg, ExitCodes exit_code) : parent(name, msg, exit_code) {} \ name(std::string name, std::string msg, ExitCodes exit_code) \
: parent(std::move(name), std::move(msg), exit_code) {} \
\ \
public: \ public: \
name(std::string msg, ExitCodes exit_code) : parent(#name, msg, exit_code) {} \ name(std::string msg, ExitCodes exit_code) : parent(#name, std::move(msg), exit_code) {} \
name(std::string msg, int exit_code) : parent(#name, msg, exit_code) {} name(std::string msg, int exit_code) : parent(#name, std::move(msg), exit_code) {}
// This is added after the one above if a class is used directly and builds its own message // This is added after the one above if a class is used directly and builds its own message
#define CLI11_ERROR_SIMPLE(name) \ #define CLI11_ERROR_SIMPLE(name) \
name(std::string msg) : name(#name, msg, ExitCodes::name) {} name(std::string msg) : name(#name, msg, ExitCodes::name) {}
namespace CLI {
/// These codes are part of every error in CLI. They can be obtained from e using e.exit_code or as a quick shortcut, /// These codes are part of every error in CLI. They can be obtained from e using e.exit_code or as a quick shortcut,
/// int values from e.get_error_code(). /// int values from e.get_error_code().
enum class ExitCodes { enum class ExitCodes {
@ -63,7 +65,7 @@ class Error : public std::runtime_error {
std::string get_name() const { return name; } std::string get_name() const { return name; }
Error(std::string name, std::string msg, int exit_code = static_cast<int>(ExitCodes::BaseClass)) Error(std::string name, std::string msg, int exit_code = static_cast<int>(ExitCodes::BaseClass))
: runtime_error(msg), exit_code(exit_code), name(name) {} : runtime_error(msg), exit_code(exit_code), name(std::move(name)) {}
Error(std::string name, std::string msg, ExitCodes exit_code) : Error(name, msg, static_cast<int>(exit_code)) {} Error(std::string name, std::string msg, ExitCodes exit_code) : Error(name, msg, static_cast<int>(exit_code)) {}
}; };