#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< CommandLineArgument > | DefaultOptionDelimiter (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 = "--" |
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
| using AZ::Settings::CommandLineParserSettings::OptionActionFunc = AZStd::function<OptionAction(AZStd::string_view option)> |
Callback function which is invoked when an option token by itself is parsed
--quiet or -verbose | using AZ::Settings::CommandLineParserSettings::OptionDelimiterFunc = AZStd::function<AZStd::optional<CommandLineArgument>(AZStd::string_view token)> |
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
| using AZ::Settings::CommandLineParserSettings::ParseCommandLineEntryFunc = AZStd::function<bool(const CommandLineArgument&)> |
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
Determines what kind of action should be taken for the option flag that was parsed An option of the form -key or –key
|
static |
Determines the default action the command line should take when it parses an option token WITHOUT a value
| option | string containing the name of the parsed command line option |
|
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
| token | to split into an option and value |
| 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
| 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
| 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"