3

私はフレームワークに取り組んでおり、コマンドラインオプションを処理するためにTCLAPを使用しています。プログラムhelpが呼び出されたときに、カテゴリに自動的にグループ化されたパラメータの使用法を出力したいと思います。出力例は次のようになります。

$ ./program help

Learning Options
    -t          Train mode
    -neg        Specifies the path for the negative examples
    -pos        Specifies the path for the positive examples

Detection Options
    -d          Detection mode
    -param      Parameters file path
    -o          Output folder
    -track      Enables tracking

Feature Extraction Options
    -w          Window size
    -feat       Feature type. Available: SIFT and SURF.

TCLAPのドキュメントを調べていましたが、何も見つかりませんでした。私はまだこのStackOverflowの投稿を調べています。私はそれがそれをしているlibobjように見えることを発見しました、しかしそれは完全に明確ではありません。

TCLAPでそれを行うにはどうすればよいですか?それが不可能な場合、私が使用できる別のライブラリはありますか?

ボーナス-TCLAPなどの小さなライブラリ:-)

4

2 に答える 2

4

私が使用できる別のライブラリはありますか?

Boost.Program_optionsライブラリを使用できます。比較的小さい (Fedora 17 では 370k)。

例はここにあります:

namespace po = boost::program_options;
// Declare the supported options.
po::options_description desc("Allowed options");
desc.add_options()
    ("help", "produce help message")
    ("compression", po::value<int>(), "set compression level")
;

po::variables_map vm;
po::store(po::parse_command_line(ac, av, desc), vm);
po::notify(vm);    

if (vm.count("help")) {
    cout << desc << "\n";
    return 1;
}

if (vm.count("compression")) {
    cout << "Compression level was set to " 
 << vm["compression"].as<int>() << ".\n";
} else {
    cout << "Compression level was not set.\n";
}
于 2012-10-09T06:21:36.430 に答える
2

Gengetoptと getopt ライブラリを使用できます。textグループ化ヘッダーを挿入できるコマンドが含まれています。良いことは、これが多くの人が知っているコマンドライン引数の GNU 規則をサポートしていることです。

于 2012-10-15T23:44:08.947 に答える