[英]Why does my program output an argument twice in usage ([-d?] and [-d|--data])? (i'm using popt library for options parsing)
程序使用兩次輸出-d
選項,盡管我在struct poptOption
中只提供了一次。 這是output的用法:
Usage: generate-test [-d?] [-d|--data] [-n|--test-name=STRING] [-?|--help]
[--usage]
--help output 是正確的:
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 庫有什么不明白的地方? 謝謝!
我同意這可能看起來令人困惑。 [-d?] [-d|--data]
顯示的popt
是-d
短選項可以是獨立選項,也可以聚合到其他短選項,例如-?
(與-n
相反)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.