From 6416df8e34cb53956bf1d562f5085eb0f2527034 Mon Sep 17 00:00:00 2001 From: "Andrii Doroshenko (Xrayez)" Date: Mon, 20 Jul 2020 00:19:05 +0300 Subject: [PATCH] Document the process of parsing command-line arguments Co-authored-by: Hugo Locurcio (cherry picked from commit df80e259cdab0ae7d89ae0b1099819ae5363b7b1) --- doc/classes/OS.xml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/doc/classes/OS.xml b/doc/classes/OS.xml index b089b03b6e5..43ddf5ef395 100644 --- a/doc/classes/OS.xml +++ b/doc/classes/OS.xml @@ -153,7 +153,18 @@ - Returns the command line arguments passed to the engine. + Returns the command-line arguments passed to the engine. + Command-line arguments can be written in any form, including both [code]--key value[/code] and [code]--key=value[/code] forms so they can be properly parsed, as long as custom command-line arguments do not conflict with engine arguments. + You can also incorporate environment variables using the [method get_environment] method. + You can set [code]editor/main_run_args[/code] in the Project Settings to define command-line arguments to be passed by the editor when running the project. + Here's a minimal example on how to parse command-line arguments into a dictionary using the [code]--key=value[/code] form for arguments: + [codeblock] + var arguments = {} + for argument in OS.get_cmdline_args(): + if argument.find("=") > -1: + var key_value = argument.split("=") + arguments[key_value[0].lstrip("--")] = key_value[1] + [/codeblock]