boostorg / boostorg/program_options

Confusing behavior when order of long/short options are swapped

Aperta
#62 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
C++
Stelle
136
Fork
117
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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`.

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Direzione di ricerca

Inizia da option_description::option_description(const char*, const value_semantic*) e dalle regole documentate sul formato dei nomi. Riproduci il comportamento nel semplice programma di test usando "h,help", quindi determina se i nomi invertiti debbano essere accettati o rifiutati esplicitamente. Il lavoro è completato quando l'uso errato non produce più il comportamento confuso a runtime e il comportamento previsto è coperto da un test.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
cpp
Ambito
cli
Tipo di issue
Bug
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.