boostorg / boostorg/program_options

Confusing behavior when order of long/short options are swapped

Đang mở
#62 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
C++
Star
136
Fork
117
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

Adding an option like this:

```cpp
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 >: unrecognised option '--help'
```

The [documentation](https://www.boost.org/doc/libs/1_66_0/doc/html/boost/program_options/option_description.html) 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`.

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Hướng nghiên cứu

Bắt đầu với option_description::option_description(const char*, const value_semantic*) và các quy tắc định dạng tên được ghi trong tài liệu. Tái hiện hành vi trong chương trình kiểm thử đơn giản bằng "h,help", sau đó xác định xem các tên bị đảo vị trí có nên được chấp nhận hay từ chối một cách tường minh hay không. Được xem là hoàn tất khi việc sử dụng sai không còn tạo ra hành vi khó hiểu trong thời gian chạy và hành vi mong muốn được một bài kiểm thử bao quát.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
cpp
Lĩnh vực
cli
Loại issue
Lỗi
Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.