No way to make the value of an option optional
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 55/100
Research direction
Start with the option declaration and parsing calls shown in optopt.lua, especially cli:option("-f, --foo=[VALUE]", ...) and cli:parse(_G.arg). Trace how an option with no supplied value is handled, then verify that an omitted flag, a bare -f, and -f buz produce the three outcomes described in the issue.
Written by the indexing model from the issue text.
Description
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
- Dominant language
- Lua
- Stars
- 129
- Forks
- 26
- Avg merge
- 1h 41m
- Merged PRs (30d)
- 1
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from lunarmodules/lua_cliargs
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
lunarmodules/lua_cliargs#85 · 1 comment ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
lunarmodules/lua_cliargs#72 · 1 comment ·
-
Difficulty 1/5 Under an hour Newbie friendliness 48/100
lunarmodules/lua_cliargs#70 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
lunarmodules/lua_cliargs#68 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
lunarmodules/lua_cliargs#67 ·
All issues in lunarmodules/lua_cliargs
Similar issues
-
ai-authored
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Data Correction Forever Needs testing/reproduction
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Questie/Questie#7941 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 78/100
-
remote remote-plugin
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day