Repository navigation
Keep the default value of a single string argument when no input is given - #98
Conversation
limbonaut
left a comment
There was a problem hiding this comment.
This introduces a regression for bound callables. For example, a method with two optional string parameters registered using command.bind("BOUND") previously received ("", "BOUND") when called without input. With this change, it receives ("BOUND", "b_def"), shifting the bound value into the first parameter. Could we restrict the early return to callables without bound arguments, or explicitly supply the first parameter’s default when arguments are bound?
|
Thanks for catching that! The early return now only applies when the callable has no bound arguments. I also added a test for the bound case (two optional string parameters with a bound value, called with and without input). |
limbonaut
left a comment
There was a problem hiding this comment.
Since we don't currently run tests, adding them without a proper test harness would only introduce unused code into the repository. Let's leave the tests out for now. The functional part is good.
|
Done, tests removed. The PR is back to the change in limbo_console.gd only. |
Fixes #76.
When a command takes a single
Stringargument, everything after the command name is joined into that argument. With no input this produced"", which replaced the argument's default value:Now, if no input is given and the argument has a default value,
_parse_argv()returns no arguments, so the method uses its default. Everything else stays the same: input is still joined into one string,testcmd ""still passes an empty string, and a single string argument without a default still gets""(so commands likeevalbehave as before). The only built-in this touches ishelp, whose default is already"".Tested in a small project with the console as an autoload, Godot 4.6.3 and 4.7.2 (headless), calling
execute_command():cmd_default(s: String = "default_value")"""default_value"cmd_static(static,s: String = "static_default")"""static_default"cmd_default hello world"hello world"cmd_default """"cmd_required(s: String, no default)""cmd_required some text"some text"cmd_two/cmd_two q 3(a: String = "a_def", b: int = 7)a_def, 7/q, 3Tested: the checks above pass on a clean checkout.