我只想接受选项的长格式选项的可选参数。
假设我定义了 option -v
,--verbose
并带有 argp 的可选参数:
static struct argp_option opt_global[] =
{
{ "verbose", 'v' , "level", OPTION_ARG_OPTIONAL, "Increase or set the verbosity level.", -1},
...
}
我现在只想在使用长选项形式时才接受可选参数。
所以
--verbose=4
将接受4
作为详细的可选参数。
但是对于短选项形式,不应接受可选参数:
| Command Line | Handled as |
|==============|===================|
| -vv | -v -v |
| -vx | -v -x |
| -v4 | -v -4 |
假设我还必须-o file
定义一个输出文件:
| Command Line | Handled as |
|==============|===================|
| -vo file | -v -o file |
| -vofile | -v -o file |
无论如何,我仍然希望帮助输出看起来像这样:
-v, --verbose[=level] Increase or set the verbosity level.
这对 GNU argp 可行吗?
通过阅读文档和玩耍,我会假设“不”,但也许我错过了一些东西。