You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 lualocalcli=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")
localopts, err=cli:parse(_G.arg)
ifnotoptsanderrthenprint(err)
os.exit(1)
endprint("foo is", opts.foo)
What I get vs. what I expect:
# as expected
$ ./optopt.lua -f buzfoo is buz
# unexpected, no option should mean no value
$ ./optopt.luafoo is fiz
# unexpected, setting the option should enable the default value if no value passed
$ ./optopt.lua -foption -f requires a value to be set
The text was updated successfully, but these errors were encountered:
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 isoptopt.lua
:What I get vs. what I expect:
The text was updated successfully, but these errors were encountered: