[英]Why does my program output an argument twice in usage ([-d?] and [-d|--data])? (i'm using popt library for options parsing)
The program usage outputs -d
option twice, though I provide it only once in struct poptOption
.程序使用两次输出
-d
选项,尽管我在struct poptOption
中只提供了一次。 This is the usage output:这是output的用法:
Usage: generate-test [-d?] [-d|--data] [-n|--test-name=STRING] [-?|--help]
[--usage]
The --help output is correct: --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
This is my code:这是我的代码:
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;
}
What do I not understand about the POpt library?我对 POpt 库有什么不明白的地方? Thanks!
谢谢!
I do agree this may look confusing.我同意这可能看起来令人困惑。 What
popt
is showing with [-d?] [-d|--data]
is that the -d
short option can be a standalone option, or it can be aggregated to other short options like -?
[-d?] [-d|--data]
显示的popt
是-d
短选项可以是独立选项,也可以聚合到其他短选项,例如-?
(contrary to -n
). (与
-n
相反)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.