I have some options that are quite verbose like -length
-strength
and I would like to allow guessing for them, so that the user can cut their names.
On the other hand some options have short names that include each other like -K1
-K10
and for those of course guessing should be disabled.
I also have a positional option and I would like to keep all the standard checks on the options: for instance I don't want to allow for unknown (mistyped) options.
I would like to know if there exists a way to achieve this with Boost::program_options...
As far as I read the docs, allow_guessing
does what you want.
In fact, it doesn't allow guessing, at all:
allow_guessing
Allow abbreviated spellings for long options, if they unambiguously identify long option. No long option name should be prefix of other long option name if guessing is in effect.
Of course the latter sounds like an alarming restriction, but it's really not. It just tells you that if you had --Kool
as well as --KoolAid
then the guessing would make even the full --Kool
ambiguous (because it could be intended as abbreviated of --KoolAid
).
--KoolA
would not be ambiguous. Neither should -K
(note the single dash) because it's not a long-form option and hence could never be an abbreviation.