使用 boost program_options,根据一个强制“模式”选择一组选项。选项
假设我有许多名为 modeA modeB common 的选项组。我将在 {} 中引用这些选项 - 即 {common} 扩展为该组中描述的任何选项。
我希望能够强制执行以下命令
command A {common} {modeA}
command B {common} {modeB}
行模式和公共组中选项的位置并不重要并且可以交织在一起
以下将失败
command A {modeB} /* Wrong option group for this mode */
command A B /* A and B not allowed */
因此目标是
- 必须发生的选项并且是集合 A|B 之一
- 如果可能的话强制作为第一个参数
- 根据上述强制参数,整个组被解析为“Ok”或被忽略
Lets presume I have a number of option groups called modeA modeB common. I'll refer to these within {} - ie {common} expands to any option described in that group.
I'd like to be able to enforce the following command lines
command A {common} {modeA}
command B {common} {modeB}
The position of options from the mode and common groups is not important and can be intertwined
The following would fail
command A {modeB} /* Wrong option group for this mode */
command A B /* A and B not allowed */
Thus the objectives are
- an option that must occur and be one of the set A|B
- if possible forced to be the first parameter
- whole groups parsed as Ok or ignored based upon the above mandatory parameter
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这不是一个优雅的解决方案,但是......
将选项至少分为三组,模式 A/模式 B 的选项和其他选项。其他包含帮助和模式选项。使用模式的自定义验证器来限制选项(使用默认值)然后
我觉得一定有更巧妙的方法
Not an elegant solution but ...
Divide the options into at least three groups, options for modeA/modeB and others. Others contain help and the mode optons. Use a custom validator for mode to limit the options (with a default) Then
I feel there must be a slicker way
我也在努力实现这一点,我能想到的最好的方法是
I am working to implement this as well, and the best I can figure is to