Skip to content

Commit fd7b310

Browse files
committed
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]
1 parent ae0ecf6 commit fd7b310

16 files changed

+4909
-443
lines changed

example/first.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ int main(int ac, char* av[])
2020
po::options_description desc("Allowed options");
2121
desc.add_options()
2222
("help", "produce help message")
23-
("compression", po::value<int>(), "set compression level")
23+
("compression", po::value<double>(), "set compression level")
2424
;
2525

2626
po::variables_map vm;
@@ -34,7 +34,7 @@ int main(int ac, char* av[])
3434

3535
if (vm.count("compression")) {
3636
cout << "Compression level was set to "
37-
<< vm["compression"].as<int>() << ".\n";
37+
<< vm["compression"].as<double>() << ".\n";
3838
} else {
3939
cout << "Compression level was not set.\n";
4040
}

include/boost/program_options/detail/cmdline.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,18 @@ namespace boost { namespace program_options { namespace detail {
8181
cmdline(int argc, const char*const * argv);
8282

8383
void style(int style);
84+
85+
/** returns the canonical option prefix associated with the command_line_style
86+
* In order of precedence:
87+
* allow_long : allow_long
88+
* allow_long_disguise : allow_long_disguise
89+
* allow_dash_for_short : allow_short | allow_dash_for_short
90+
* allow_slash_for_short: allow_short | allow_slash_for_short
91+
*
92+
* This is mainly used for the diagnostic messages in exceptions
93+
*/
94+
int get_canonical_option_prefix();
95+
8496
void allow_unregistered();
8597

8698
void set_options_description(const options_description& desc);

include/boost/program_options/detail/parsers.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,11 @@ namespace boost { namespace program_options {
100100
basic_parsed_options<charT>
101101
basic_command_line_parser<charT>::run()
102102
{
103-
parsed_options result(m_desc);
103+
// save the canonical prefixes which were used by this cmdline parser
104+
// eventually inside the parsed results
105+
// This will be handy to format recognisable options
106+
// for diagnostic messages if everything blows up much later on
107+
parsed_options result(m_desc, detail::cmdline::get_canonical_option_prefix());
104108
result.options = detail::cmdline::run();
105109

106110
// Presense of parsed_options -> wparsed_options conversion

0 commit comments

Comments
 (0)