Open 3D Engine AzCore API Reference 25.10.0
O3DE is an open-source, fully-featured, high-fidelity, modular 3D engine for building games and simulations, available to every industry.
AZ::Settings::CommandLineParserSettings Struct Reference

#include <CommandLineParser.h>

Public Types

enum class  OptionAction { NextTokenIsValueIfNonOption , IsFlag , NextTokenIsValue }
 
using ParseCommandLineEntryFunc = AZStd::function< bool(const CommandLineArgument &)>
 
using OptionActionFunc = AZStd::function< OptionAction(AZStd::string_view option)>
 
using OptionDelimiterFunc = AZStd::function< AZStd::optional< CommandLineArgument >(AZStd::string_view token)>
 

Static Public Member Functions

static OptionAction DefaultOptionAction (AZStd::string_view option)
 
static AZStd::optional< CommandLineArgumentDefaultOptionDelimiter (AZStd::string_view token)
 

Public Attributes

ParseCommandLineEntryFunc m_parseCommandLineEntryFunc
 Callback function which is invoked with the parsed command line argument.
 
OptionActionFunc m_optionActionFunc = &DefaultOptionAction
 
OptionDelimiterFunc m_optionDelimiterFunc = &DefaultOptionDelimiter
 Function which is invoked to split an option into an option name and option value pair.
 
CommandLineOptionPrefixArray m_optionPrefixes { Platform::GetDefaultOptionPrefixes() }
 
AZStd::string_view m_positionalArgSeparator = "--"
 

Detailed Description

Settings structure which is used to parse CLI command line parameters It is setup to invoke an callback with each argument option name and value to allow parsing of the command line without allocating any heap memory This can be used to parse the command line in order to read in settings which can configure memory allocators before they are available without the need to allocate any heap memory as long as the user supplied callback itself is careful in how it stores its settings. Suggestion: Use structures such as fixed_vector and fixed_string to store the settings in the user callback to avoid heap allocations and rely entirely on stack memory instead

Member Typedef Documentation

◆ OptionActionFunc

Callback function which is invoked when an option token by itself is parsed

Returns
The type of action to take for the option, which is to either parse the next command line token as the value for the option or treat the option as just a CLI flag, such as --quiet or -verbose

◆ OptionDelimiterFunc

Callback function which is invoked when an option argument(-short=value or –long=value) is processed to split the the option into an option name value pair

Returns
Argument containing the option name and Token

◆ ParseCommandLineEntryFunc

Callback invoked for positional argument or a completed option argument. A completed option argument will contain any value associated with the option name This is the the only member that is required to be set within this struct All other members are defaulted to work with command line arguments IMPORTANT: Any lambda functions or class instances that are larger than 16 bytes in size requires a memory allocation to store. So it is recommended that users binding a lambda bind at most 2 reference or pointer members to avoid dynamic heap allocations

Returns
True should be returned from this function to indicate that parsing of the config entry has succeeded

Member Enumeration Documentation

◆ OptionAction

Determines what kind of action should be taken for the option flag that was parsed An option of the form -key or –key

Enumerator
NextTokenIsValueIfNonOption 

This indicates that the next "non-option" token should be parsed as the value for the current option being parsed A non-option token is one that doesn't start with an option prefix such as '-' or '–' For a token sequence of --project-path <value> "<value>" is used as value for "project-path" option However for a token sequence of --project-path --project-cache-path <value> the "project-path" option uses "" as its value because the very next token is an option of "--project-cache-path" the "project-cache-path" does have its value set to "<value>"

IsFlag 

This indicates that the option is a flag and contains no additional value parameters For a token sequence of --force <value> The "force" option uses a value of "". This allows the user to treated is a flag option The "<value>" token in this case is treated as positional parameter

Member Function Documentation

◆ DefaultOptionAction()

static OptionAction AZ::Settings::CommandLineParserSettings::DefaultOptionAction ( AZStd::string_view  option)
static

Determines the default action the command line should take when it parses an option token WITHOUT a value

Parameters
optionstring containing the name of the parsed command line option
Returns
The default action to take for the option. The default return value is to treat the next command line token as the value for the option string

◆ DefaultOptionDelimiter()

static AZStd::optional< CommandLineArgument > AZ::Settings::CommandLineParserSettings::DefaultOptionDelimiter ( AZStd::string_view  token)
static

Splits a command line option token into an option and value Surrounding whitespace around the key and value are not part of the string views

Parameters
tokento split into an option and value
Returns
option, value pair structure representing the command line argument option name and value

Member Data Documentation

◆ m_optionActionFunc

OptionActionFunc AZ::Settings::CommandLineParserSettings::m_optionActionFunc = &DefaultOptionAction

Function invoked ONLY after parsing an option Token that was not split from a CLI delimiter such as an '=' The algorithm that determines when this function is called is explained with the following sample command line arguments ‘Editor --project-path=<project-path> --force --engine-path <engine-path> positionalArgument For the "project-path" option, this function is NOT invoked since the value is gathered by spliting the CLI token on ’=' result: option="project-path", value="<project-path>" For the "force" option, this function IS invoked to determine how the next token should be treated If the function returns OptionAction::NextTokenIsValueIfNonOption, then the following "--engine-path" token is read as an option. If the function returns OptionAction::IsFlag, then the following "--engine-path" token is read as an option. If the function returns OptionAction::NextTokenIsValue, then the following "--engine-path" token is treated as the value for the "force" option

◆ m_optionPrefixes

CommandLineOptionPrefixArray AZ::Settings::CommandLineParserSettings::m_optionPrefixes { Platform::GetDefaultOptionPrefixes() }

By default the option prefixes are "--" and "-" NOTE: The order is important here as double dash is checked first before single dash to make sure an argument such as --foo bar parses both dashes before the option name. Otherwise the option name would be parsed as "-foo" which is incorrect. The correct parsing is "foo" for the option name

◆ m_positionalArgSeparator

AZStd::string_view AZ::Settings::CommandLineParserSettings::m_positionalArgSeparator = "--"

Separator which is used to separate normal argument parsing(option/positional) from just positional argument parsing Positional arguments can still be parsed before the separator, however options will not be parsed (i.e -- --foo bar) will parse --foo as a positional argument not an option with a value of "bar"


The documentation for this struct was generated from the following file: