class CommandLine

Provides access to command-line arguments passed to the application.

Supports parsing parameters in various formats: -param, --param, /param, -param=value, --param=value, /param:value.

Public

Methods

staticInitialize

static void Initialize(int argc, char *argv[])

Initialize the command-line from argc/argv (Unix-style).

argc
Argument count.
argv
Argument values.

staticInitialize

static void Initialize(const String &commandLine)

Initialize the command-line from a single string (Windows-style).

commandLine
The full command-line string including executable path.

staticGet

static const String &Get()

Gets the full command-line string (excluding executable path).

staticGetExecutablePath

static const Path &GetExecutablePath()

Get the executable path from the command-line.

Returns: The full path to the executable (e.g., "C:\Program Files\MyApp\MyApp.exe").

staticGetArgumentCount

static u32 GetArgumentCount()

Get the number of arguments (excluding executable).

Returns: The argument count.

staticGetArgument

static const String &GetArgument(u32 index)

Get argument at specific index (0-based, excluding executable).

index
The argument index (0-based).

Returns: The argument string, or empty string if index is out of bounds.

staticHasParameter

static bool HasParameter(const String &name)

Check if a parameter exists on the command-line.

Supports formats: -param, --param, /param (case-insensitive).

name
The parameter name.

Returns: True if the parameter exists, false otherwise.

staticGetParameterValue

static String GetParameterValue(const String &name, const String &defaultValue = StringUtility::kBlank)

Get parameter value as string.

Supports formats: -param=value, --param=value, /param:value, -param value.

name
The parameter name.
defaultValue
The default value if parameter doesn't exist.

Returns: The parameter value, or default value if not found.

staticGetParameterValueAsInt

static i32 GetParameterValueAsInt(const String &name, i32 defaultValue = 0)

Get parameter value as integer.

name
The parameter name.
defaultValue
The default value if parameter doesn't exist or isn't a valid integer.

Returns: The parameter value as integer.

staticGetParameterValueAsFloat

static float GetParameterValueAsFloat(const String &name, float defaultValue = 0.F)

Get parameter value as float.

name
The parameter name.
defaultValue
The default value if parameter doesn't exist or isn't a valid float.

Returns: The parameter value as float.

staticGetParameterValueAsBool

static bool GetParameterValueAsBool(const String &name, bool defaultValue = false)

Get parameter value as boolean.

Accepts: true/false, 1/0, yes/no, on/off (case-insensitive). Switches without values return true.

name
The parameter name.
defaultValue
The default value if parameter doesn't exist.

Returns: The parameter value as boolean.

staticGetAllParameters

static const UnorderedMap<String, String> &GetAllParameters()

Get all command-line parameters as a map.

Keys are normalized to lowercase.

Returns: Const reference to the parameters map.

Private

Methods

staticParse

static void Parse(const TArray<String> &tokens)

Parse the command-line with proper quote and escape character handling.

Populates sArguments and sParameters.