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.
我有一些非常冗长的选项,如-length -strength,我想允许猜测它们,以便用户可以剪切它们的名字。
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.
另一方面,一些选项具有短名称,其中包括-K1 -K10,对于那些当然猜测应该被禁用。
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...
我想知道是否存在使用Boost :: program_options实现此目的的方法...
1 个解决方案
#1
1
As far as I read the docs, allow_guessing
does what you want.
就我阅读文档而言,allow_guessing可以做你想要的。
In fact, it doesn't allow guessing, at all:
事实上,它根本不允许猜测:
allow_guessing
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
).
当然后者听起来像是一个惊人的限制,但事实并非如此。它只是告诉你,如果你有--Kool以及--KoolAid那么猜测甚至会使整个--Kool模糊不清(因为它可能是缩写为-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.
--KoolA不会含糊不清。也不应该-K(注意单个破折号),因为它不是长形式选项,因此永远不能是缩写。
#1
1
As far as I read the docs, allow_guessing
does what you want.
就我阅读文档而言,allow_guessing可以做你想要的。
In fact, it doesn't allow guessing, at all:
事实上,它根本不允许猜测:
allow_guessing
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
).
当然后者听起来像是一个惊人的限制,但事实并非如此。它只是告诉你,如果你有--Kool以及--KoolAid那么猜测甚至会使整个--Kool模糊不清(因为它可能是缩写为-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.
--KoolA不会含糊不清。也不应该-K(注意单个破折号),因为它不是长形式选项,因此永远不能是缩写。