-
-
Notifications
You must be signed in to change notification settings - Fork 103
Description
Describe the project you are working on
The Godot editor 🙂
Describe the problem or limitation you are having in your project
There are two types of command line arguments supported by Godot:
- Engine command line arguments such as
-eand--fullscreen. These can be read usingOS.get_cmdline_args(), which does not return user command line arguments. - User command line arguments, which are specified after
--or++. These can be read usingOS.get_cmdline_user_args(), which does not return engine command line arguments.
See #2797 for context on why this separation was made in 4.0.
This system works well for most cases (it follows the standard UNIX command line scheme where -- on its own is a delimiter for arguments to be passed to a subprogram). However, it has its limitations. One of these limitations is that you can only pass user command line arguments at the end of the command line. This strict ordering can be a problem for plugins that wish to pass user command line arguments when running a project, as evidenced in godotengine/godot#107671 (review).
Describe the feature / enhancement and how it helps to overcome the problem or limitation
Allow specifying user command-line arguments in an order-independent manner. The current approach to specifying user command line arguments would remain supported.
A common approach popularized by id Tech and Source is to use - for engine command line arguments, and + for game-specific (user) command line arguments:
-novid -nojoy +map de_dust2
This approach uses prefixes to distinguish between engine and user command line arguments, which means no delimiter like -- is needed.
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
OS.get_cmdline_user_args() would now return arguments that are placed before --/++ if they start with a +. For arguments that you explicitly want to remain as engine arguments (such as file names), this can be bypassed by putting the value in quotes.
The prefix remains as-is in the returned array of values, so it's up to the script reading the arguments to handle any style differences here (e.g. if you wish to allow both + and -- prefixes for user arguments, but only + would be usable before the --/++ separator).
Conversely, OS.get_cmdline_args() would not return arguments that are placed before --/++ if they start with a +.
The following command lines are all valid:
godot --fullscreen -- --level=1
# Engine arguments: ["--fullscreen"]
# User arguments: ["--level=1"]
godot --fullscreen +level=1
# Engine arguments: ["--fullscreen"]
# User arguments: ["+level=1"]
godot +level=1 --fullscreen
# Engine arguments: ["--fullscreen"]
# User arguments: ["+level=1"]
godot +level=1 --fullscreen -- --level=1
# Engine arguments: ["--fullscreen"]
# User arguments: ["+level=1", "--level=1"]
# (It's up to the script to handle conflicts/priority of arguments.)If this enhancement will not be used often, can it be worked around with a few lines of script?
No.
Is there a reason why this should be core and not an add-on in the asset library?
This is about improving the flexibility of the command line. Also, command line argument parsing happens in main.cpp, which can't be overridden by add-ons since it's very early in the Godot initialization stage.