Opened 16 years ago

Closed 16 years ago

Last modified 10 years ago

#860 closed Bugs (Invalid)

program_options: long options use prefix only

Reported by: goldwynr Owned by: nobody
Milestone: Component: None
Version: None Severity: Problem
Keywords: Cc:

Description

Using program_options defaults, while scanning for long_options, only the prefix is used.

So long options which begin with the same alphabets result in ambiguous results.

A program which takes --foo(-f), --fool(-l), --fooled(-d) as options currently works like the following:

~/program_options_tests$ ./a.out -f
foo option selected
~/program_options_tests$ ./a.out -l
fool option selected
~/program_options_tests$ ./a.out -d
fooled option selected
~/program_options_tests$ ./a.out --fo
error: ambiguous option fo
~/program_options_tests$ ./a.out --foo
error: ambiguous option foo
~/program_options_tests$ ./a.out --fool
error: ambiguous option fool
~/program_options_tests$ ./a.out --foole
fooled option selected
~/program_options_tests$ ./a.out --fooled
fooled option selected

Expected results:
----------------
./a.out --foo
./a.out --fool
./a.out --fooled 
should have been valid options

./a.out --foole
should have been an invalid option


Actual Results:
--------------
./a.out --foo
./a.out --fool
failed.

./a.out --foole
was accepted as --fooled option.

The program used is attached.


Change History (5)

comment:1 by Vladimir Prus, 16 years ago

Status: assignedclosed
Logged In: YES 
user_id=321498
Originator: NO

Thanks for the report!

You can disable this behaviour by passing the 'style' parameter to the parse_command_line function explicitly, and using 'default_style ^ allow_guessing' for the style. This will disable guessing of long options based on prefix completely.

If that still does not solve you problem, feel free to reopen this issue.

comment:2 by mgruenke, 16 years ago

Logged In: YES 
user_id=343027
Originator: NO

Shouldn't it provide compatible behavior with getopt_long(), by default?  I consider it a bug that (by default) it accepts longopts I didn't specify, regardless of whether there's any shadowing of other options.

comment:3 by Vladimir Prus, 16 years ago

Logged In: YES 
user_id=321498
Originator: NO

I don't think getopt_long is something we're required to emulate. It looks that whether this is bug or not is not clear, so I'm gonna close this bug report, at least until more users come and complain.

comment:4 by anonymous, 15 years ago

I'll complain too ;-) I think the default settings should work as the original poster expected.

comment:5 by jotik, 10 years ago

Severity: Problem

Me too.

Note: See TracTickets for help on using tickets.