Skip to content

Keep the default value of a single string argument when no input is given - #98

Merged
limbonaut merged 3 commits into
limbonaut:masterfrom
vladosskins178:fix/single-string-arg-default
Nov 6, 2026
Merged

limbonaut merged 3 commits into
limbonaut:masterfrom
vladosskins178:fix/single-string-arg-default

Conversation

@vladosskins178

@vladosskins178 vladosskins178 commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #76.

When a command takes a single String argument, everything after the command name is joined into that argument. With no input this produced "", which replaced the argument's default value:

static func testcmd(str: String = "default_value") -> void:
	print(str)  # `testcmd` printed "" instead of "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 like eval behave as before). The only built-in this touches is help, 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():

Command line master this PR
cmd_default (s: String = "default_value") "" "default_value"
cmd_static (static, s: String = "static_default") "" "static_default"
cmd_default hello world "hello world" same
cmd_default "" "" same
cmd_required (s: String, no default) "" same
cmd_required some text "some text" same
cmd_two / cmd_two q 3 (a: String = "a_def", b: int = 7) a_def, 7 / q, 3 same

Tested: the checks above pass on a clean checkout.

@limbonaut limbonaut left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@vladosskins178

Copy link
Copy Markdown
Contributor Author

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 limbonaut left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@vladosskins178

Copy link
Copy Markdown
Contributor Author

Done, tests removed. The PR is back to the change in limbo_console.gd only.

@limbonaut
limbonaut merged commit e013a37 into limbonaut:master Nov 6, 2026
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

Successfully merging this pull request may close these issues.

Command with optional default value overwrites default value when no-arg version is used

2 participants