Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
duyanning opened this issue Dec 1, 2023 · 7 comments

Comments

@duyanning
Copy link
Contributor

duyanning commented Dec 1, 2023

根据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
Copy link
Contributor Author

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

也就是,必须写等号。

@duyanning
Copy link
Contributor Author

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

@Issues-translate-bot
Copy link

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
Copy link
Member

waruqi commented Dec 1, 2023

可以

@Issues-translate-bot
Copy link

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


Can

@duyanning
Copy link
Contributor Author

#251

@Issues-translate-bot
Copy link

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


#251

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants