boostorg / boostorg/program_options
Confusing behavior when order of long/short options are swapped
- Lenguaje dominante
- C++
- Estrellas
- 136
- Forks
- 117
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Descripción
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`.
Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
Línea de trabajo
Comienza con option_description::option_description(const char*, const value_semantic*) y las reglas documentadas para el formato de los nombres. Reproduce el comportamiento en el programa de prueba sencillo usando "h,help" y, después, determina si los nombres intercambiados deben aceptarse o rechazarse explícitamente. Se considera terminado cuando el uso incorrecto ya no produce el comportamiento confuso en tiempo de ejecución y el comportamiento previsto está cubierto por una prueba.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- cpp
- Área
- cli
- Tipo de issue
- Error
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100