Confusing behavior when order of long/short options are swapped

未关闭
#62 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
cpp
领域
cli

调研方向

从 option_description::option_description(const char*, const value_semantic*) 和文档中规定的名称格式规则开始。使用 "h,help" 在简单测试程序中复现该行为,然后确定是否应明确接受或拒绝交换顺序的名称。完成的标准是:误用不再产生令人困惑的运行时行为,并且预期行为已由测试覆盖。

由索引模型根据 Issue 内容生成。

描述

Adding an option like this:

desc.add_options()( "h,help", "Print help and exit" );

In a simple test program and then trying to use --help results in a confusing error:

$ ./prog --help
libc++abi.dylib: terminating with uncaught exception of type boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::program_options::unknown_option> >: unrecognised option '--help'

The documentation for option_description::option_description(const char*, const value_semantic*) says:

The 'name' parameter is interpreted by the following rules:
if there's no "," character in 'name', it specifies long name
otherwise, the part before "," specifies long name and the part after -- short name.

However, it is easy for new users of this library to think that swapping them is OK.

The reason for this limitation isn't clear to me -- presumably, if one is "long" and the other "short", providing them in either order should be OK, and a simple test can tell which is which. In either case, the error message on misuse is needlessly cryptic and could probably be turned into an error thrown from option_description::option_description. This seems reasonable, since using "h,help" as the option name results in bad behavior regardless: the resulting executable has options --h and -h.

主要语言
C++
星标
136
派生
117
PR 合并指标
30 天内没有已合并 PR

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

boostorg/program_options 的其他 Issue

查看 boostorg/program_options 的全部 Issue

相似的 Issue

更多 C++ Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。