clang-tidy fixes (#231)
This commit is contained in:
parent
b0f67a06de
commit
12bc8d78e7
@ -25,8 +25,8 @@ THE SOFTWARE.
|
|||||||
#ifndef CXXOPTS_HPP_INCLUDED
|
#ifndef CXXOPTS_HPP_INCLUDED
|
||||||
#define CXXOPTS_HPP_INCLUDED
|
#define CXXOPTS_HPP_INCLUDED
|
||||||
|
|
||||||
#include <cstring>
|
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
|
#include <cstring>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
@ -37,6 +37,7 @@ THE SOFTWARE.
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#ifdef __cpp_lib_optional
|
#ifdef __cpp_lib_optional
|
||||||
@ -61,7 +62,7 @@ namespace cxxopts
|
|||||||
CXXOPTS__VERSION_MINOR,
|
CXXOPTS__VERSION_MINOR,
|
||||||
CXXOPTS__VERSION_PATCH
|
CXXOPTS__VERSION_PATCH
|
||||||
};
|
};
|
||||||
}
|
} // namespace cxxopts
|
||||||
|
|
||||||
//when we ask cxxopts to use Unicode, help strings are processed using ICU,
|
//when we ask cxxopts to use Unicode, help strings are processed using ICU,
|
||||||
//which results in the correct lengths being computed for strings when they
|
//which results in the correct lengths being computed for strings when they
|
||||||
@ -227,9 +228,9 @@ namespace cxxopts
|
|||||||
|
|
||||||
inline
|
inline
|
||||||
String&
|
String&
|
||||||
stringAppend(String&s, String a)
|
stringAppend(String&s, const String& a)
|
||||||
{
|
{
|
||||||
return s.append(std::move(a));
|
return s.append(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline
|
inline
|
||||||
@ -259,7 +260,7 @@ namespace cxxopts
|
|||||||
{
|
{
|
||||||
return s.empty();
|
return s.empty();
|
||||||
}
|
}
|
||||||
}
|
} // namespace cxxopts
|
||||||
|
|
||||||
//ifdef CXXOPTS_USE_UNICODE
|
//ifdef CXXOPTS_USE_UNICODE
|
||||||
#endif
|
#endif
|
||||||
@ -275,7 +276,7 @@ namespace cxxopts
|
|||||||
const std::string LQUOTE("‘");
|
const std::string LQUOTE("‘");
|
||||||
const std::string RQUOTE("’");
|
const std::string RQUOTE("’");
|
||||||
#endif
|
#endif
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
class Value : public std::enable_shared_from_this<Value>
|
class Value : public std::enable_shared_from_this<Value>
|
||||||
{
|
{
|
||||||
@ -324,13 +325,13 @@ namespace cxxopts
|
|||||||
class OptionException : public std::exception
|
class OptionException : public std::exception
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
OptionException(const std::string& message)
|
explicit OptionException(std::string message)
|
||||||
: m_message(message)
|
: m_message(std::move(message))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual const char*
|
const char*
|
||||||
what() const noexcept
|
what() const noexcept override
|
||||||
{
|
{
|
||||||
return m_message.c_str();
|
return m_message.c_str();
|
||||||
}
|
}
|
||||||
@ -343,7 +344,7 @@ namespace cxxopts
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
OptionSpecException(const std::string& message)
|
explicit OptionSpecException(const std::string& message)
|
||||||
: OptionException(message)
|
: OptionException(message)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -352,7 +353,7 @@ namespace cxxopts
|
|||||||
class OptionParseException : public OptionException
|
class OptionParseException : public OptionException
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
OptionParseException(const std::string& message)
|
explicit OptionParseException(const std::string& message)
|
||||||
: OptionException(message)
|
: OptionException(message)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -361,7 +362,7 @@ namespace cxxopts
|
|||||||
class option_exists_error : public OptionSpecException
|
class option_exists_error : public OptionSpecException
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
option_exists_error(const std::string& option)
|
explicit option_exists_error(const std::string& option)
|
||||||
: OptionSpecException("Option " + LQUOTE + option + RQUOTE + " already exists")
|
: OptionSpecException("Option " + LQUOTE + option + RQUOTE + " already exists")
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -370,7 +371,7 @@ namespace cxxopts
|
|||||||
class invalid_option_format_error : public OptionSpecException
|
class invalid_option_format_error : public OptionSpecException
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
invalid_option_format_error(const std::string& format)
|
explicit invalid_option_format_error(const std::string& format)
|
||||||
: OptionSpecException("Invalid option format " + LQUOTE + format + RQUOTE)
|
: OptionSpecException("Invalid option format " + LQUOTE + format + RQUOTE)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -378,7 +379,7 @@ namespace cxxopts
|
|||||||
|
|
||||||
class option_syntax_exception : public OptionParseException {
|
class option_syntax_exception : public OptionParseException {
|
||||||
public:
|
public:
|
||||||
option_syntax_exception(const std::string& text)
|
explicit option_syntax_exception(const std::string& text)
|
||||||
: OptionParseException("Argument " + LQUOTE + text + RQUOTE +
|
: OptionParseException("Argument " + LQUOTE + text + RQUOTE +
|
||||||
" starts with a - but has incorrect syntax")
|
" starts with a - but has incorrect syntax")
|
||||||
{
|
{
|
||||||
@ -388,7 +389,7 @@ namespace cxxopts
|
|||||||
class option_not_exists_exception : public OptionParseException
|
class option_not_exists_exception : public OptionParseException
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
option_not_exists_exception(const std::string& option)
|
explicit option_not_exists_exception(const std::string& option)
|
||||||
: OptionParseException("Option " + LQUOTE + option + RQUOTE + " does not exist")
|
: OptionParseException("Option " + LQUOTE + option + RQUOTE + " does not exist")
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -397,7 +398,7 @@ namespace cxxopts
|
|||||||
class missing_argument_exception : public OptionParseException
|
class missing_argument_exception : public OptionParseException
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
missing_argument_exception(const std::string& option)
|
explicit missing_argument_exception(const std::string& option)
|
||||||
: OptionParseException(
|
: OptionParseException(
|
||||||
"Option " + LQUOTE + option + RQUOTE + " is missing an argument"
|
"Option " + LQUOTE + option + RQUOTE + " is missing an argument"
|
||||||
)
|
)
|
||||||
@ -408,7 +409,7 @@ namespace cxxopts
|
|||||||
class option_requires_argument_exception : public OptionParseException
|
class option_requires_argument_exception : public OptionParseException
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
option_requires_argument_exception(const std::string& option)
|
explicit option_requires_argument_exception(const std::string& option)
|
||||||
: OptionParseException(
|
: OptionParseException(
|
||||||
"Option " + LQUOTE + option + RQUOTE + " requires an argument"
|
"Option " + LQUOTE + option + RQUOTE + " requires an argument"
|
||||||
)
|
)
|
||||||
@ -436,7 +437,7 @@ namespace cxxopts
|
|||||||
class option_not_present_exception : public OptionParseException
|
class option_not_present_exception : public OptionParseException
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
option_not_present_exception(const std::string& option)
|
explicit option_not_present_exception(const std::string& option)
|
||||||
: OptionParseException("Option " + LQUOTE + option + RQUOTE + " not present")
|
: OptionParseException("Option " + LQUOTE + option + RQUOTE + " not present")
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -445,7 +446,7 @@ namespace cxxopts
|
|||||||
class argument_incorrect_type : public OptionParseException
|
class argument_incorrect_type : public OptionParseException
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
argument_incorrect_type
|
explicit argument_incorrect_type
|
||||||
(
|
(
|
||||||
const std::string& arg
|
const std::string& arg
|
||||||
)
|
)
|
||||||
@ -459,7 +460,7 @@ namespace cxxopts
|
|||||||
class option_required_exception : public OptionParseException
|
class option_required_exception : public OptionParseException
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
option_required_exception(const std::string& option)
|
explicit option_required_exception(const std::string& option)
|
||||||
: OptionParseException(
|
: OptionParseException(
|
||||||
"Option " + LQUOTE + option + RQUOTE + " is required but not present"
|
"Option " + LQUOTE + option + RQUOTE + " is required but not present"
|
||||||
)
|
)
|
||||||
@ -497,7 +498,7 @@ namespace cxxopts
|
|||||||
("(t|T)(rue)?|1");
|
("(t|T)(rue)?|1");
|
||||||
std::basic_regex<char> falsy_pattern
|
std::basic_regex<char> falsy_pattern
|
||||||
("(f|F)(alse)?|0");
|
("(f|F)(alse)?|0");
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
namespace detail
|
namespace detail
|
||||||
{
|
{
|
||||||
@ -542,7 +543,7 @@ namespace cxxopts
|
|||||||
{
|
{
|
||||||
SignedCheck<T, std::numeric_limits<T>::is_signed>()(negative, value, text);
|
SignedCheck<T, std::numeric_limits<T>::is_signed>()(negative, value, text);
|
||||||
}
|
}
|
||||||
}
|
} // namespace detail
|
||||||
|
|
||||||
template <typename R, typename T>
|
template <typename R, typename T>
|
||||||
R
|
R
|
||||||
@ -745,7 +746,7 @@ namespace cxxopts
|
|||||||
{
|
{
|
||||||
std::stringstream in(text);
|
std::stringstream in(text);
|
||||||
std::string token;
|
std::string token;
|
||||||
while(in.eof() == false && std::getline(in, token, CXXOPTS_VECTOR_DELIMITER)) {
|
while(!in.eof() && std::getline(in, token, CXXOPTS_VECTOR_DELIMITER)) {
|
||||||
T v;
|
T v;
|
||||||
parse_value(token, v);
|
parse_value(token, v);
|
||||||
value.emplace_back(std::move(v));
|
value.emplace_back(std::move(v));
|
||||||
@ -798,12 +799,12 @@ namespace cxxopts
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract_value(T* t)
|
explicit abstract_value(T* t)
|
||||||
: m_store(t)
|
: m_store(t)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~abstract_value() = default;
|
~abstract_value() override = default;
|
||||||
|
|
||||||
abstract_value(const abstract_value& rhs)
|
abstract_value(const abstract_value& rhs)
|
||||||
{
|
{
|
||||||
@ -824,37 +825,37 @@ namespace cxxopts
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
parse(const std::string& text) const
|
parse(const std::string& text) const override
|
||||||
{
|
{
|
||||||
parse_value(text, *m_store);
|
parse_value(text, *m_store);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
is_container() const
|
is_container() const override
|
||||||
{
|
{
|
||||||
return type_is_container<T>::value;
|
return type_is_container<T>::value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
parse() const
|
parse() const override
|
||||||
{
|
{
|
||||||
parse_value(m_default_value, *m_store);
|
parse_value(m_default_value, *m_store);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
has_default() const
|
has_default() const override
|
||||||
{
|
{
|
||||||
return m_default;
|
return m_default;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
has_implicit() const
|
has_implicit() const override
|
||||||
{
|
{
|
||||||
return m_implicit;
|
return m_implicit;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Value>
|
std::shared_ptr<Value>
|
||||||
default_value(const std::string& value)
|
default_value(const std::string& value) override
|
||||||
{
|
{
|
||||||
m_default = true;
|
m_default = true;
|
||||||
m_default_value = value;
|
m_default_value = value;
|
||||||
@ -862,7 +863,7 @@ namespace cxxopts
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Value>
|
std::shared_ptr<Value>
|
||||||
implicit_value(const std::string& value)
|
implicit_value(const std::string& value) override
|
||||||
{
|
{
|
||||||
m_implicit = true;
|
m_implicit = true;
|
||||||
m_implicit_value = value;
|
m_implicit_value = value;
|
||||||
@ -870,26 +871,26 @@ namespace cxxopts
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Value>
|
std::shared_ptr<Value>
|
||||||
no_implicit_value()
|
no_implicit_value() override
|
||||||
{
|
{
|
||||||
m_implicit = false;
|
m_implicit = false;
|
||||||
return shared_from_this();
|
return shared_from_this();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
get_default_value() const
|
get_default_value() const override
|
||||||
{
|
{
|
||||||
return m_default_value;
|
return m_default_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
get_implicit_value() const
|
get_implicit_value() const override
|
||||||
{
|
{
|
||||||
return m_implicit_value;
|
return m_implicit_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
is_boolean() const
|
is_boolean() const override
|
||||||
{
|
{
|
||||||
return std::is_same<T, bool>::value;
|
return std::is_same<T, bool>::value;
|
||||||
}
|
}
|
||||||
@ -901,10 +902,7 @@ namespace cxxopts
|
|||||||
{
|
{
|
||||||
return *m_result;
|
return *m_result;
|
||||||
}
|
}
|
||||||
else
|
return *m_store;
|
||||||
{
|
|
||||||
return *m_store;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -935,21 +933,21 @@ namespace cxxopts
|
|||||||
class standard_value<bool> : public abstract_value<bool>
|
class standard_value<bool> : public abstract_value<bool>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
~standard_value() = default;
|
~standard_value() override = default;
|
||||||
|
|
||||||
standard_value()
|
standard_value()
|
||||||
{
|
{
|
||||||
set_default_and_implicit();
|
set_default_and_implicit();
|
||||||
}
|
}
|
||||||
|
|
||||||
standard_value(bool* b)
|
explicit standard_value(bool* b)
|
||||||
: abstract_value(b)
|
: abstract_value(b)
|
||||||
{
|
{
|
||||||
set_default_and_implicit();
|
set_default_and_implicit();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Value>
|
std::shared_ptr<Value>
|
||||||
clone() const
|
clone() const override
|
||||||
{
|
{
|
||||||
return std::make_shared<standard_value<bool>>(*this);
|
return std::make_shared<standard_value<bool>>(*this);
|
||||||
}
|
}
|
||||||
@ -965,7 +963,7 @@ namespace cxxopts
|
|||||||
m_implicit_value = "true";
|
m_implicit_value = "true";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
} // namespace values
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
std::shared_ptr<Value>
|
std::shared_ptr<Value>
|
||||||
@ -988,15 +986,15 @@ namespace cxxopts
|
|||||||
public:
|
public:
|
||||||
OptionDetails
|
OptionDetails
|
||||||
(
|
(
|
||||||
const std::string& short_,
|
std::string short_,
|
||||||
const std::string& long_,
|
std::string long_,
|
||||||
const String& desc,
|
String desc,
|
||||||
std::shared_ptr<const Value> val
|
std::shared_ptr<const Value> val
|
||||||
)
|
)
|
||||||
: m_short(short_)
|
: m_short(std::move(short_))
|
||||||
, m_long(long_)
|
, m_long(std::move(long_))
|
||||||
, m_desc(desc)
|
, m_desc(std::move(desc))
|
||||||
, m_value(val)
|
, m_value(std::move(val))
|
||||||
, m_count(0)
|
, m_count(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -1073,7 +1071,7 @@ namespace cxxopts
|
|||||||
void
|
void
|
||||||
parse
|
parse
|
||||||
(
|
(
|
||||||
std::shared_ptr<const OptionDetails> details,
|
const std::shared_ptr<const OptionDetails>& details,
|
||||||
const std::string& text
|
const std::string& text
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@ -1083,7 +1081,7 @@ namespace cxxopts
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
parse_default(std::shared_ptr<const OptionDetails> details)
|
parse_default(const std::shared_ptr<const OptionDetails>& details)
|
||||||
{
|
{
|
||||||
ensure_value(details);
|
ensure_value(details);
|
||||||
m_default = true;
|
m_default = true;
|
||||||
@ -1120,7 +1118,7 @@ namespace cxxopts
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void
|
void
|
||||||
ensure_value(std::shared_ptr<const OptionDetails> details)
|
ensure_value(const std::shared_ptr<const OptionDetails>& details)
|
||||||
{
|
{
|
||||||
if (m_value == nullptr)
|
if (m_value == nullptr)
|
||||||
{
|
{
|
||||||
@ -1175,7 +1173,7 @@ namespace cxxopts
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
ParseResult(
|
ParseResult(
|
||||||
const std::shared_ptr<
|
std::shared_ptr<
|
||||||
std::unordered_map<std::string, std::shared_ptr<OptionDetails>>
|
std::unordered_map<std::string, std::shared_ptr<OptionDetails>>
|
||||||
>,
|
>,
|
||||||
std::vector<std::string>,
|
std::vector<std::string>,
|
||||||
@ -1226,18 +1224,18 @@ namespace cxxopts
|
|||||||
add_to_option(const std::string& option, const std::string& arg);
|
add_to_option(const std::string& option, const std::string& arg);
|
||||||
|
|
||||||
bool
|
bool
|
||||||
consume_positional(std::string a);
|
consume_positional(const std::string& a);
|
||||||
|
|
||||||
void
|
void
|
||||||
parse_option
|
parse_option
|
||||||
(
|
(
|
||||||
std::shared_ptr<OptionDetails> value,
|
const std::shared_ptr<OptionDetails>& value,
|
||||||
const std::string& name,
|
const std::string& name,
|
||||||
const std::string& arg = ""
|
const std::string& arg = ""
|
||||||
);
|
);
|
||||||
|
|
||||||
void
|
void
|
||||||
parse_default(std::shared_ptr<OptionDetails> details);
|
parse_default(const std::shared_ptr<OptionDetails>& details);
|
||||||
|
|
||||||
void
|
void
|
||||||
checked_parse_arg
|
checked_parse_arg
|
||||||
@ -1245,7 +1243,7 @@ namespace cxxopts
|
|||||||
int argc,
|
int argc,
|
||||||
char* argv[],
|
char* argv[],
|
||||||
int& current,
|
int& current,
|
||||||
std::shared_ptr<OptionDetails> value,
|
const std::shared_ptr<OptionDetails>& value,
|
||||||
const std::string& name
|
const std::string& name
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -1266,15 +1264,15 @@ namespace cxxopts
|
|||||||
{
|
{
|
||||||
Option
|
Option
|
||||||
(
|
(
|
||||||
const std::string& opts,
|
std::string opts,
|
||||||
const std::string& desc,
|
std::string desc,
|
||||||
const std::shared_ptr<const Value>& value = ::cxxopts::value<bool>(),
|
std::shared_ptr<const Value> value = ::cxxopts::value<bool>(),
|
||||||
const std::string& arg_help = ""
|
std::string arg_help = ""
|
||||||
)
|
)
|
||||||
: opts_(opts)
|
: opts_(std::move(opts))
|
||||||
, desc_(desc)
|
, desc_(std::move(desc))
|
||||||
, value_(value)
|
, value_(std::move(value))
|
||||||
, arg_help_(arg_help)
|
, arg_help_(std::move(arg_help))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1286,11 +1284,10 @@ namespace cxxopts
|
|||||||
|
|
||||||
class Options
|
class Options
|
||||||
{
|
{
|
||||||
typedef std::unordered_map<std::string, std::shared_ptr<OptionDetails>>
|
using OptionMap = std::unordered_map<std::string, std::shared_ptr<OptionDetails>>;
|
||||||
OptionMap;
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Options(std::string program, std::string help_string = "")
|
explicit Options(std::string program, std::string help_string = "")
|
||||||
: m_program(std::move(program))
|
: m_program(std::move(program))
|
||||||
, m_help_string(toLocalString(std::move(help_string)))
|
, m_help_string(toLocalString(std::move(help_string)))
|
||||||
, m_custom_help("[OPTION...]")
|
, m_custom_help("[OPTION...]")
|
||||||
@ -1357,7 +1354,7 @@ namespace cxxopts
|
|||||||
const std::string& s,
|
const std::string& s,
|
||||||
const std::string& l,
|
const std::string& l,
|
||||||
std::string desc,
|
std::string desc,
|
||||||
std::shared_ptr<const Value> value,
|
const std::shared_ptr<const Value>& value,
|
||||||
std::string arg_help
|
std::string arg_help
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -1380,7 +1377,7 @@ namespace cxxopts
|
|||||||
std::string
|
std::string
|
||||||
help(const std::vector<std::string>& groups = {}) const;
|
help(const std::vector<std::string>& groups = {}) const;
|
||||||
|
|
||||||
const std::vector<std::string>
|
std::vector<std::string>
|
||||||
groups() const;
|
groups() const;
|
||||||
|
|
||||||
const HelpGroupDetails&
|
const HelpGroupDetails&
|
||||||
@ -1392,7 +1389,7 @@ namespace cxxopts
|
|||||||
add_one_option
|
add_one_option
|
||||||
(
|
(
|
||||||
const std::string& option,
|
const std::string& option,
|
||||||
std::shared_ptr<OptionDetails> details
|
const std::shared_ptr<OptionDetails>& details
|
||||||
);
|
);
|
||||||
|
|
||||||
String
|
String
|
||||||
@ -1438,7 +1435,7 @@ namespace cxxopts
|
|||||||
(
|
(
|
||||||
const std::string& opts,
|
const std::string& opts,
|
||||||
const std::string& desc,
|
const std::string& desc,
|
||||||
std::shared_ptr<const Value> value
|
const std::shared_ptr<const Value>& value
|
||||||
= ::cxxopts::value<bool>(),
|
= ::cxxopts::value<bool>(),
|
||||||
std::string arg_help = ""
|
std::string arg_help = ""
|
||||||
);
|
);
|
||||||
@ -1465,12 +1462,12 @@ namespace cxxopts
|
|||||||
const HelpOptionDetails& o
|
const HelpOptionDetails& o
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
auto& s = o.s;
|
const auto& s = o.s;
|
||||||
auto& l = o.l;
|
const auto& l = o.l;
|
||||||
|
|
||||||
String result = " ";
|
String result = " ";
|
||||||
|
|
||||||
if (s.size() > 0)
|
if (!s.empty())
|
||||||
{
|
{
|
||||||
result += "-" + toLocalString(s) + ",";
|
result += "-" + toLocalString(s) + ",";
|
||||||
}
|
}
|
||||||
@ -1479,12 +1476,12 @@ namespace cxxopts
|
|||||||
result += " ";
|
result += " ";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (l.size() > 0)
|
if (!l.empty())
|
||||||
{
|
{
|
||||||
result += " --" + toLocalString(l);
|
result += " --" + toLocalString(l);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto arg = o.arg_help.size() > 0 ? toLocalString(o.arg_help) : "arg";
|
auto arg = !o.arg_help.empty() ? toLocalString(o.arg_help) : "arg";
|
||||||
|
|
||||||
if (!o.is_boolean)
|
if (!o.is_boolean)
|
||||||
{
|
{
|
||||||
@ -1513,7 +1510,7 @@ namespace cxxopts
|
|||||||
|
|
||||||
if (o.has_default && (!o.is_boolean || o.default_value != "false"))
|
if (o.has_default && (!o.is_boolean || o.default_value != "false"))
|
||||||
{
|
{
|
||||||
if(o.default_value != "")
|
if(!o.default_value.empty())
|
||||||
{
|
{
|
||||||
desc += toLocalString(" (default: " + o.default_value + ")");
|
desc += toLocalString(" (default: " + o.default_value + ")");
|
||||||
}
|
}
|
||||||
@ -1576,19 +1573,19 @@ namespace cxxopts
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
inline
|
inline
|
||||||
ParseResult::ParseResult
|
ParseResult::ParseResult
|
||||||
(
|
(
|
||||||
const std::shared_ptr<
|
std::shared_ptr<
|
||||||
std::unordered_map<std::string, std::shared_ptr<OptionDetails>>
|
std::unordered_map<std::string, std::shared_ptr<OptionDetails>>
|
||||||
> options,
|
> options,
|
||||||
std::vector<std::string> positional,
|
std::vector<std::string> positional,
|
||||||
bool allow_unrecognised,
|
bool allow_unrecognised,
|
||||||
int& argc, char**& argv
|
int& argc, char**& argv
|
||||||
)
|
)
|
||||||
: m_options(options)
|
: m_options(std::move(options))
|
||||||
, m_positional(std::move(positional))
|
, m_positional(std::move(positional))
|
||||||
, m_next_positional(m_positional.begin())
|
, m_next_positional(m_positional.begin())
|
||||||
, m_allow_unrecognised(allow_unrecognised)
|
, m_allow_unrecognised(allow_unrecognised)
|
||||||
@ -1624,7 +1621,7 @@ OptionAdder::operator()
|
|||||||
(
|
(
|
||||||
const std::string& opts,
|
const std::string& opts,
|
||||||
const std::string& desc,
|
const std::string& desc,
|
||||||
std::shared_ptr<const Value> value,
|
const std::shared_ptr<const Value>& value,
|
||||||
std::string arg_help
|
std::string arg_help
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@ -1657,10 +1654,7 @@ OptionAdder::operator()
|
|||||||
{
|
{
|
||||||
return std::make_tuple(long_.str(), short_.str());
|
return std::make_tuple(long_.str(), short_.str());
|
||||||
}
|
}
|
||||||
else
|
return std::make_tuple(short_.str(), long_.str());
|
||||||
{
|
|
||||||
return std::make_tuple(short_.str(), long_.str());
|
|
||||||
}
|
|
||||||
}(short_match, long_match);
|
}(short_match, long_match);
|
||||||
|
|
||||||
m_options.add_option
|
m_options.add_option
|
||||||
@ -1678,7 +1672,7 @@ OptionAdder::operator()
|
|||||||
|
|
||||||
inline
|
inline
|
||||||
void
|
void
|
||||||
ParseResult::parse_default(std::shared_ptr<OptionDetails> details)
|
ParseResult::parse_default(const std::shared_ptr<OptionDetails>& details)
|
||||||
{
|
{
|
||||||
m_results[details].parse_default(details);
|
m_results[details].parse_default(details);
|
||||||
}
|
}
|
||||||
@ -1687,7 +1681,7 @@ inline
|
|||||||
void
|
void
|
||||||
ParseResult::parse_option
|
ParseResult::parse_option
|
||||||
(
|
(
|
||||||
std::shared_ptr<OptionDetails> value,
|
const std::shared_ptr<OptionDetails>& value,
|
||||||
const std::string& /*name*/,
|
const std::string& /*name*/,
|
||||||
const std::string& arg
|
const std::string& arg
|
||||||
)
|
)
|
||||||
@ -1705,7 +1699,7 @@ ParseResult::checked_parse_arg
|
|||||||
int argc,
|
int argc,
|
||||||
char* argv[],
|
char* argv[],
|
||||||
int& current,
|
int& current,
|
||||||
std::shared_ptr<OptionDetails> value,
|
const std::shared_ptr<OptionDetails>& value,
|
||||||
const std::string& name
|
const std::string& name
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@ -1750,7 +1744,7 @@ ParseResult::add_to_option(const std::string& option, const std::string& arg)
|
|||||||
|
|
||||||
inline
|
inline
|
||||||
bool
|
bool
|
||||||
ParseResult::consume_positional(std::string a)
|
ParseResult::consume_positional(const std::string& a)
|
||||||
{
|
{
|
||||||
while (m_next_positional != m_positional.end())
|
while (m_next_positional != m_positional.end())
|
||||||
{
|
{
|
||||||
@ -1766,22 +1760,13 @@ ParseResult::consume_positional(std::string a)
|
|||||||
++m_next_positional;
|
++m_next_positional;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
++m_next_positional;
|
||||||
{
|
continue;
|
||||||
++m_next_positional;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
add_to_option(*m_next_positional, a);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
add_to_option(*m_next_positional, a);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
else
|
throw_or_mimic<option_not_exists_exception>(*m_next_positional);
|
||||||
{
|
|
||||||
throw_or_mimic<option_not_exists_exception>(*m_next_positional);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@ -1808,7 +1793,7 @@ inline
|
|||||||
void
|
void
|
||||||
Options::parse_positional(std::initializer_list<std::string> options)
|
Options::parse_positional(std::initializer_list<std::string> options)
|
||||||
{
|
{
|
||||||
parse_positional(std::vector<std::string>(std::move(options)));
|
parse_positional(std::vector<std::string>(options));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline
|
inline
|
||||||
@ -1882,11 +1867,8 @@ ParseResult::parse(int& argc, char**& argv)
|
|||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else
|
//error
|
||||||
{
|
throw_or_mimic<option_not_exists_exception>(name);
|
||||||
//error
|
|
||||||
throw_or_mimic<option_not_exists_exception>(name);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto value = iter->second;
|
auto value = iter->second;
|
||||||
@ -1923,11 +1905,8 @@ ParseResult::parse(int& argc, char**& argv)
|
|||||||
++current;
|
++current;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else
|
//error
|
||||||
{
|
throw_or_mimic<option_not_exists_exception>(name);
|
||||||
//error
|
|
||||||
throw_or_mimic<option_not_exists_exception>(name);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto opt = iter->second;
|
auto opt = iter->second;
|
||||||
@ -1954,7 +1933,7 @@ ParseResult::parse(int& argc, char**& argv)
|
|||||||
for (auto& opt : *m_options)
|
for (auto& opt : *m_options)
|
||||||
{
|
{
|
||||||
auto& detail = opt.second;
|
auto& detail = opt.second;
|
||||||
auto& value = detail->value();
|
const auto& value = detail->value();
|
||||||
|
|
||||||
auto& store = m_results[detail];
|
auto& store = m_results[detail];
|
||||||
|
|
||||||
@ -2004,19 +1983,19 @@ Options::add_option
|
|||||||
const std::string& s,
|
const std::string& s,
|
||||||
const std::string& l,
|
const std::string& l,
|
||||||
std::string desc,
|
std::string desc,
|
||||||
std::shared_ptr<const Value> value,
|
const std::shared_ptr<const Value>& value,
|
||||||
std::string arg_help
|
std::string arg_help
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
auto stringDesc = toLocalString(std::move(desc));
|
auto stringDesc = toLocalString(std::move(desc));
|
||||||
auto option = std::make_shared<OptionDetails>(s, l, stringDesc, value);
|
auto option = std::make_shared<OptionDetails>(s, l, stringDesc, value);
|
||||||
|
|
||||||
if (s.size() > 0)
|
if (!s.empty())
|
||||||
{
|
{
|
||||||
add_one_option(s, option);
|
add_one_option(s, option);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (l.size() > 0)
|
if (!l.empty())
|
||||||
{
|
{
|
||||||
add_one_option(l, option);
|
add_one_option(l, option);
|
||||||
}
|
}
|
||||||
@ -2037,7 +2016,7 @@ void
|
|||||||
Options::add_one_option
|
Options::add_one_option
|
||||||
(
|
(
|
||||||
const std::string& option,
|
const std::string& option,
|
||||||
std::shared_ptr<OptionDetails> details
|
const std::shared_ptr<OptionDetails>& details
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
auto in = m_options->emplace(option, details);
|
auto in = m_options->emplace(option, details);
|
||||||
@ -2052,7 +2031,7 @@ inline
|
|||||||
String
|
String
|
||||||
Options::help_one_group(const std::string& g) const
|
Options::help_one_group(const std::string& g) const
|
||||||
{
|
{
|
||||||
typedef std::vector<std::pair<String, String>> OptionHelp;
|
using OptionHelp = std::vector<std::pair<String, String>>;
|
||||||
|
|
||||||
auto group = m_help.find(g);
|
auto group = m_help.find(g);
|
||||||
if (group == m_help.end())
|
if (group == m_help.end())
|
||||||
@ -2151,7 +2130,7 @@ Options::generate_all_groups_help(String& result) const
|
|||||||
std::vector<std::string> all_groups;
|
std::vector<std::string> all_groups;
|
||||||
all_groups.reserve(m_help.size());
|
all_groups.reserve(m_help.size());
|
||||||
|
|
||||||
for (auto& group : m_help)
|
for (const auto& group : m_help)
|
||||||
{
|
{
|
||||||
all_groups.push_back(group.first);
|
all_groups.push_back(group.first);
|
||||||
}
|
}
|
||||||
@ -2166,13 +2145,13 @@ Options::help(const std::vector<std::string>& help_groups) const
|
|||||||
String result = m_help_string + "\nUsage:\n " +
|
String result = m_help_string + "\nUsage:\n " +
|
||||||
toLocalString(m_program) + " " + toLocalString(m_custom_help);
|
toLocalString(m_program) + " " + toLocalString(m_custom_help);
|
||||||
|
|
||||||
if (m_positional.size() > 0 && m_positional_help.size() > 0) {
|
if (!m_positional.empty() && !m_positional_help.empty()) {
|
||||||
result += " " + toLocalString(m_positional_help);
|
result += " " + toLocalString(m_positional_help);
|
||||||
}
|
}
|
||||||
|
|
||||||
result += "\n\n";
|
result += "\n\n";
|
||||||
|
|
||||||
if (help_groups.size() == 0)
|
if (help_groups.empty())
|
||||||
{
|
{
|
||||||
generate_all_groups_help(result);
|
generate_all_groups_help(result);
|
||||||
}
|
}
|
||||||
@ -2185,7 +2164,7 @@ Options::help(const std::vector<std::string>& help_groups) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline
|
inline
|
||||||
const std::vector<std::string>
|
std::vector<std::string>
|
||||||
Options::groups() const
|
Options::groups() const
|
||||||
{
|
{
|
||||||
std::vector<std::string> g;
|
std::vector<std::string> g;
|
||||||
@ -2210,6 +2189,6 @@ Options::group_help(const std::string& group) const
|
|||||||
return m_help.at(group);
|
return m_help.at(group);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace cxxopts
|
||||||
|
|
||||||
#endif //CXXOPTS_HPP_INCLUDED
|
#endif //CXXOPTS_HPP_INCLUDED
|
||||||
|
Loading…
Reference in New Issue
Block a user