No way to make the value of an option optional
还没有人认领这个 Issue。
评估
调研方向
从 optopt.lua 中显示的选项声明和解析调用开始,尤其是 cli:option("-f, --foo=[VALUE]", ...) 和 cli:parse(_G.arg)。跟踪未提供值的选项是如何处理的,然后验证省略 flag、单独使用 -f 以及 -f buz 是否会产生 issue 中描述的三种结果。
由索引模型根据 Issue 内容生成。
描述
In the 2.x series of releases it was possible to setup an option that had no value if not set, a default value if just the flag was added but no value given, and additionally a custom value if a value was passed. In 3.x this does not seem to be possible. Flags cannot take values and options always require a value. The default for options is only parsed in the event the option flag is not even passed.
As an example, I would like the value of a --foo=[VALUE] option to be optional with a default value if set, but allow the user to set (or not set) foo. If this is optopt.lua:
#!/usr/bin/env lua
local cli = require("cliargs")
cli:set_name("optopt")
cli:set_description("optional arg test")
cli:option("-f, --foo=[VALUE]", "foo val default to fiz", "fiz")
cli:flag("-h, --help", "display this help, then exit")
local opts, err = cli:parse(_G.arg)
if not opts and err then
print(err)
os.exit(1)
end
print("foo is", opts.foo)
What I get vs. what I expect:
# as expected
$ ./optopt.lua -f buz
foo is buz
# unexpected, no option should mean no value
$ ./optopt.lua
foo is fiz
# unexpected, setting the option should enable the default value if no value passed
$ ./optopt.lua -f
option -f requires a value to be set
- 主要语言
- Lua
- 星标
- 129
- 派生
- 26
- 平均合并
- 1 小时 41 分钟
- 30 天内合并 PR
- 1
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
lunarmodules/lua_cliargs 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 68/100
lunarmodules/lua_cliargs#85 · 1 条评论 ·
-
Parsing --help needs to return something other than an error可能已有人在做 @TheMagician23 于 1031 天前认领。 未关闭
难度 4/5 3-5 天 新手友好度 35/100
lunarmodules/lua_cliargs#72 · 1 条评论 ·
-
Option to accept multiple options not documented可能已有人在做 @copilot-swe-agent 于 69 天前认领。 未关闭
难度 1/5 1 小时以内 新手友好度 48/100
lunarmodules/lua_cliargs#70 ·
-
难度 3/5 1-2 天 新手友好度 35/100
lunarmodules/lua_cliargs#68 ·
-
难度 3/5 1-2 天 新手友好度 45/100
lunarmodules/lua_cliargs#67 ·
查看 lunarmodules/lua_cliargs 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
-
难度 2/5 1-3 小时 新手友好度 62/100
维护者通常 3 天内回复
-
[Operation Enhancement]: .editorconfigと.gitattributesでdictionaryとLuaファイルの編集・改行設定を統一する可能已有人在做 @5kdn 今天认领。 未关闭
难度 1/5 1 小时以内 新手友好度 80/100
5kdn/DCS-Translation-Japanese#163 ·
维护者通常 1 天内回复
-
[Bug Report]未关闭area/Cubelet area/CubeNet bug needs-triage needs:compliance
难度 2/5 1-3 小时 新手友好度 62/100
TencentCloud/CubeSandbox#1917 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 66/100