私はBoost.program_optionsを使用して、POSIXユーティリティの実装にコマンドラインを解析しています。簡単な例として、cmp
を取ってください。--help出力でコマンドラインオペランドの説明を表示する方法
ここでは、すべての引数の説明を表示する追加の引数--help
が必要です。これはこの場合重要です。私が持っている:file1
とfile2
オプションの説明を表示することができません
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;
}
を。もちろん、それらをoptions
に追加することはできますが、これは少なくとも2つの望ましくない引数[-]-file{1,2}
を追加します。これは本当に嫌いです。私は(明らかにそれをハードコーディングせず)--help
ために、この出力をしたい:
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.
は、ライブラリの周りにハッキングすることなく、これを達成する方法はありますか?私はこれがかなり基本的なものだと思うだろうが、私はtutorialsのどれかでそれを見つけることができない。
UPDATE皆様のご協力のために、feature requestを提出しました。
悪いニュース、残念ながら ':(' – rubenvb