【发布时间】:2021-01-13 02:19:04
【问题描述】:
我想只接受长格式的选项的可选参数 的选项。
假设我使用 argp 的可选参数定义了选项 -v、--verbose:
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 可行吗?
通过阅读文档和玩耍,我会假设“不”,但也许我 错过了什么。
【问题讨论】:
-
Is this doable with GNU argp?“这个”到底是什么?-vo是否作为-v -o处理? -
@KamilCuk 我试图澄清。希望这会更好。