Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#11392 closed Bugs (fixed)

boost::program_options accepting switch-options that match the beginning of defined option, but is not full option typed out.

Reported by: eg@… Owned by: Vladimir Prus
Milestone: To Be Determined Component: program_options
Version: Boost 1.57.0 Severity: Problem
Keywords: Cc:

Description

With:

namespace po = boost::program_options; po::options_description desc ("options"); desc.add_options ()

( "help,h", "print this help message") ( "config,c", po::value<ustring>(), "config file, default: $XDG_CONFIG_HOME/astroid/config") ( "new-config,n", "make new default config, then exit") ( "mailto,m", po::value<ustring>(), "compose mail with mailto url or address") ( "no-auto-poll", "do not poll automatically");

po::variables_map vm;

bool show_help = false;

try {

po::store ( po::parse_command_line (argc, argv, desc), vm );

} catch (po::unknown_option &ex) {

cout << "unknown option" << endl; cout << ex.what() << endl; show_help = true;

}

running:

./program --asdf

fails, but running:

./program --hel

is parsed as --help.

Change History (5)

comment:1 by John Maddock, 7 years ago

Component: Noneprogram_options
Owner: set to Vladimir Prus

comment:2 by Vladimir Prus, 7 years ago

Thanks for the report!

Why do you believe this to be a bug? The default_style, defined in cmdline.hpp, does include "allow_guessing" bit, so it appears the library behaves as designed.

comment:3 by eg@…, 7 years ago

Oh, darn. Didn't realize it was configurable. Thanks for the explanation!

gaute

comment:4 by Vladimir Prus, 7 years ago

Resolution: fixed
Status: newclosed

Good that this turned to be easy to solve!

comment:3 by eg@…, 7 years ago

Oh, darn. Didn't realize it was configurable. Thanks for the explanation!

gaute

Note: See TracTickets for help on using tickets.