c - 为什么我的程序在使用时会输出两次参数([-d?] 和 [-d|--data])?(我正在使用 popt 库进行选项解析)
问题描述
程序用法输出-d
选项两次,尽管我在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 库有什么不明白的地方?谢谢!
解决方案
我同意这可能看起来令人困惑。popt
所显示的[-d?] [-d|--data]
是空头-d
期权可以是一个独立的期权,或者它可以聚合到其他空头期权,例如-?
(与 相反-n
)。
推荐阅读
- java - java.sql.SQLSyntaxErrorException:用户缺少权限或找不到对象:
- php - 强制 file_get_contents 或 stream_socket_client 使用所需的 dns 服务器
- java - 带有泛型参数接口的回调
- c - snprintf() 是否通过格式说明符使用根内存?
- android - Android 如何防止使用快速键盘?
- node.js - 通过 HTTPS 在 NodeJS 后端上的 Angular
- java - 如何在 JavaFx 中使表格视图的每个单元格可编辑
- jquery - JQuery Rails 更新属性不起作用
- python - 如何在 sqlalchemist Python 的 ORM 中构建这个 postgresql 查询?
- wordpress - Wordpress 联系表 7 标签不会被替换