プログラムの使用法-d
はオプションを 2 回出力しますが、私は で 1 回しか提供しませんstruct poptOption
。これは使用法の出力です:
Usage: generate-test [-d?] [-d|--data] [-n|--test-name=STRING] [-?|--help]
[--usage]
--help 出力は正しいです:
Usage: generate-test [OPTION...]
-d, --data Provide this option if the test needs external data from file(s)
-n, --test-name=STRING Provide a test name, this option is mandatory
Help options:
-?, --help Show this help message
--usage Display brief usage message
これは私のコードです:
char *test_name = NULL;
int use_external_data = 0;
struct poptOption popt_options[] = {
{"data", 'd', POPT_ARG_NONE, NULL, 2, "Provide this option if the test needs an external data from file(s)", NULL },
{"test-name", 'n', POPT_ARG_STRING, &test_name, 1, "Provide a test name, this option is mandatory", NULL },
POPT_AUTOHELP { NULL, '\0', 0, NULL, 0, NULL, NULL }
};
poptContext popt_context;
popt_context = poptGetContext("Test generator", argc, argv, popt_options, 0);
int opt_ret = 0;
while ((opt_ret = poptGetNextOpt(popt_context)) > 0)
switch (opt_ret)
{
case 2:
use_external_data = 1;
break;
}
POpt ライブラリについてわからないことは何ですか? ありがとう!