tboox / tbox

🎁 A glib-like multi-platform c library
https://docs.tboox.org
Apache License 2.0
4.89k stars 725 forks source link

tb_option_done 只认 -f=a.txt 这种形式,却不认 -f a.txt 这种形式 #250

Closed duyanning closed 12 months ago

duyanning commented 1 year ago

根据TB_OPTION_MODE_KEY_VAL的文档 tb_option_done能够支持以下2种风格的命令行参数: -k=value -k value

但我发现,只要缺了 = 号,tb_option_done就会抱怨。

当我运行 build/linux/x86_64/debug/myapp -f=a.txt 时,看到如下抱怨: [tbox]: [option]: [error]: myapp: no option value '--f=' at tb_option_done(): 466, src/tbox/utils/option.c

下面是我的option ` static tb_option_item_t g_options[] = { { 'f' , "config" , TB_OPTION_MODE_KEY_VAL , TB_OPTION_TYPE_CSTR , "加载指定配置文件" } , {'h', "help", TB_OPTION_MODE_KEY, TB_OPTION_TYPE_BOOL, "显式本帮助信息并退出"} , {'-', tb_null, TB_OPTION_MODE_MORE, TB_OPTION_TYPE_NONE, tb_null} };

`

期待的结果

build/linux/x86_64/debug/myapp -f=a.txt 时不报错

错误信息

[tbox]: [option]: [error]: myapp: no option value '--f=' at tb_option_done(): 466, src/tbox/utils/option.c

相关环境

Debian GNU/Linux 12 (bookworm) gcc (Debian 12.2.0-14) 12.2.0

其他信息

duyanning commented 1 year ago

我在 tb_option_done 的源码里看到,tbox目前是采用这种方式获取选项的value的: tb_char_t val = (p == '=')? (p + 1) : tb_null;

也就是,必须写等号。

duyanning commented 1 year ago

请问作者,我是否可以修改代码以支持无等号的形式? 如果可以的话,后边我或许可以提交一个pull request。

Issues-translate-bot commented 1 year ago

Bot detected the issue body's language is not English, translate it automatically.


I would like to ask the author, can I modify the code to support the form without equal sign? If possible, I might be able to submit a pull request later.

waruqi commented 1 year ago

可以

Issues-translate-bot commented 1 year ago

Bot detected the issue body's language is not English, translate it automatically.


Can

duyanning commented 1 year ago

251

Issues-translate-bot commented 1 year ago

Bot detected the issue body's language is not English, translate it automatically.


251