Sto utilizzando Boost.program_options per analizzare le righe di comando per l'implementazione dei programmi di utilità POSIX. Come semplice esempio, prendi cmp
.Come visualizzare la descrizione dell'operando della riga di comando in --help output
Ora mi piacerebbe avere un argomento aggiuntivo --help
che mostra una descrizione di tutti gli argomenti, che è importante in questo caso. Ho:
po::options_description options("Options");
options.add_options()("help", "Show this help output.")
(",l", "(Lowercase ell.) Write the byte number (decimal) and the differing bytes (octal) for each difference.")
(",s", "Write nothing for differing files; return exit status only.")
po::positional_options_description operands;
operands.add("file1", 1);//, "A pathname of the first file to be compared. If file1 is '-', the standard input shall be used.")
operands.add("file2", 1);//, "A pathname of the second file to be compared. If file2 is '-', the standard input shall be used.");
po::variables_map vm;
po::store(po::command_line_parser(argc, argv).options(options).positional(operands).run(), vm);
po::notify(vm);
if(vm.count("help"))
{
std::cout << "cmp: compare two files\nUsage: cmp [ -l | -s ] file1 file2\n" << options;
return 0;
}
che è in grado di mostrare le descrizione file1
e file2
opzioni. Posso ovviamente aggiungerli a options
, ma questo aggiungerebbe almeno due argomenti indesiderati [-]-file{1,2}
, che davvero non desidero. Voglio solo che questa uscita per --help
(senza hardcoding ovviamente):
cmp: compare two files
Usage: cmp [ -l | -s ] file1 file2
Options:
--help Show this help output.
-l (Lowercase ell.) Write the byte number (decimal) and the differing bytes (octal) for each difference.
-s Write nothing for differing files; return exit status only.
Operands:
file1 A pathname of the first file to be compared. If file1 is '-', the standard input shall be used.
file2 A pathname of the second file to be compared. If file2 is '-', the standard input shall be used.
Esiste un modo per raggiungere questo obiettivo, senza l'hacking intorno alla biblioteca? Penso che si tratti di cose piuttosto semplici, ma non riesco a trovarlo in nessuno degli tutorials.
UPDATE a beneficio di tutti, ho presentato una feature request per questo, in un certo senso si spera retrocompatibile.
Cattive notizie, sfortunatamente ': (' – rubenvb