Improve error reporting.

The name of option is now shown in most cases when it's feasible, and
clarify of the error messages has been improved throughout.

Patch from Leo Goodstadt.


[SVN r77827]
This commit is contained in:
Vladimir Prus
2012-04-08 08:42:39 +00:00
parent ae0ecf6581
commit fd7b310993
16 changed files with 4957 additions and 491 deletions

View File

@@ -137,6 +137,31 @@ namespace boost { namespace program_options {
return m_short_name;
}
std::string
option_description::canonical_display_name(int prefix_style) const
{
if (!m_long_name.empty())
{
if (prefix_style == command_line_style::allow_long)
return "--" + m_long_name;
if (prefix_style == command_line_style::allow_long_disguise)
return "-" + m_long_name;
}
// sanity check: m_short_name[0] should be '-' or '/'
if (m_short_name.length() == 2)
{
if (prefix_style == command_line_style::allow_slash_for_short)
return string("/") + m_short_name[1];
if (prefix_style == command_line_style::allow_dash_for_short)
return string("-") + m_short_name[1];
}
if (!m_long_name.empty())
return m_long_name;
else
return m_short_name;
}
const std::string&
option_description::long_name() const
{
@@ -292,7 +317,7 @@ namespace boost { namespace program_options {
const option_description* d = find_nothrow(name, approx,
long_ignore_case, short_ignore_case);
if (!d)
boost::throw_exception(unknown_option(name));
boost::throw_exception(unknown_option());
return *d;
}
@@ -340,8 +365,7 @@ namespace boost { namespace program_options {
}
}
if (full_matches.size() > 1)
boost::throw_exception(
ambiguous_option(name, full_matches));
boost::throw_exception(ambiguous_option(full_matches));
// If we have a full match, and an approximate match,
// ignore approximate match instead of reporting error.
@@ -349,8 +373,7 @@ namespace boost { namespace program_options {
// "--all" on the command line should select the first one,
// without ambiguity.
if (full_matches.empty() && approximate_matches.size() > 1)
boost::throw_exception(
ambiguous_option(name, approximate_matches));
boost::throw_exception(ambiguous_option(approximate_matches));
return found.get();
}
@@ -399,7 +422,7 @@ namespace boost { namespace program_options {
if (count(par.begin(), par.end(), '\t') > 1)
{
boost::throw_exception(program_options::error(
"Only one tab per paragraph is allowed"));
"Only one tab per paragraph is allowed in the options description"));
}
// erase tab from string