简体   繁体   English

为什么我的程序 output 使用两次参数([-d?] 和 [-d|--data])? (我正在使用 popt 库进行选项解析)

[英]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.

相关问题 popt库使用 - popt Library usage 为什么 %d 在我的 c 程序 output 中显示 0? - Why %d is showing 0 in my c program output? 为什么我的程序没有显示任何 output? 0 个错误,0 个警告但没有 output? 我正在使用 Dev C++ 编译器 - Why is my program not showing any output? 0 errors, 0 warnings but no output? I'm using Dev C++ compiler 为什么我的程序在我按 ctrl + D 时会在它结束之前打印一些东西? - Why does my program print something before it ends when I press ctrl + D? 当我的程序从Linux上的标准输入读取CTRL-D时,为什么不将其转换为EOF? - When my program reads CTRL-D from standard input on Linux, why does it not convert to EOF? 为什么printf会在我的程序中输出? - Why does printf output this in my program? 当字符串太短时,为什么会弹出pop segfault? - Why does popt segfault when a string is too short? 使用互斥时,“printf”输出两次(或更多?我不确定)? - when using mutex, “printf” output twice(or more?I'm not sure)? 使用fscanf()读取每行3个数字的文件,为什么“%d%d%d%* c”与“%d%d%d”一样好? - Using fscanf() to read a file with lines of 3 numbers each,why does “%d%d%d%*c” act as good as “%d%d%d”? 为什么我的C程序会输出这个? - Why does my C program output this?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM