#include <CommandLine.h>
Classes | |
struct | CommandArgument |
Public Types | |
using | ParamContainer = AZStd::vector< AZStd::string > |
using | ArgumentVector = AZStd::vector< CommandArgument > |
Public Member Functions | |
AZ_CLASS_ALLOCATOR (CommandLine, AZ::SystemAllocator) | |
CommandLine (AZStd::string_view commandLineOptionPrefix) | |
void | Parse (int argc, char **argv) |
void | Parse (AZStd::span< const AZStd::string_view > commandLine) |
void | Parse (const ParamContainer &commandLine) |
void | Dump (ParamContainer &commandLineDumpOutput) const |
bool | HasSwitch (AZStd::string_view switchName) const |
AZStd::size_t | GetNumSwitchValues (AZStd::string_view switchName) const |
const AZStd::string & | GetSwitchValue (AZStd::string_view switchName) const |
const AZStd::string & | GetSwitchValue (AZStd::string_view switchName, AZStd::size_t index) const |
AZStd::size_t | GetNumMiscValues () const |
const AZStd::string & | GetMiscValue (AZStd::size_t index) const |
bool | empty () const |
auto | size () const -> ArgumentVector::size_type |
auto | begin () -> ArgumentVector::iterator |
auto | begin () const -> ArgumentVector::const_iterator |
auto | cbegin () const -> ArgumentVector::const_iterator |
auto | end () -> ArgumentVector::iterator |
auto | end () const -> ArgumentVector::const_iterator |
auto | cend () const -> ArgumentVector::const_iterator |
auto | rbegin () -> ArgumentVector::reverse_iterator |
auto | rbegin () const -> ArgumentVector::const_reverse_iterator |
auto | crbegin () const -> ArgumentVector::const_reverse_iterator |
auto | rend () -> ArgumentVector::reverse_iterator |
auto | rend () const -> ArgumentVector::const_reverse_iterator |
auto | crend () const -> ArgumentVector::const_reverse_iterator |
Given a commandline, this allows uniform parsing of it into parameter values and extra values. When parsed, the commandline becomes a series of "options" or "extra values" For example, a option may be specified as either /optionName=value1[,value2...] /optionname value[,value2...] –optionname value[,value2...] or other combinations of the above You may NOT use a colon as a option separator since file names may easily contain them. any additional parameters which are not associated with any option are considered "misc values"
NOTE: "flags" options which doesn't specify a value need care when using This is because the Parse() methods don't accept external metadata indicating actions to perform on flag arguments unlike python argparse https://docs.python.org/3/library/argparse.html#action For example the command line of app.exe --verbose <PositionalArg>
would parse <PositionalArg> as the value of the "verbose" flag The workaround is to either
app.exe <PositionalArg> --verbose
app.exe --verbose --count 2 <PositionalArg>
app.exe --verbose 1 <PositionalArg>
or app.exe --verbose=1 <PositionalArg>
AZ::CommandLine::CommandLine | ( | AZStd::string_view | commandLineOptionPrefix | ) |
Initializes a CommandLine instance which uses the provided commandLineOptionPreix for parsing switches
void AZ::CommandLine::Dump | ( | ParamContainer & | commandLineDumpOutput | ) | const |
Will dump command line parameters from the CommandLine in a format such that switches are prefixed with the option prefix followed by their value(s) which are comma separated The result of this function can be supplied to Parse() to re-create an equivalent command line object Ex, If the command line has the current list of parsed miscellaneous values and switches of MiscValue = ["Foo", "Bat"] Switches = ["GameFolder" : [], "RemoteIp" : ["10.0.0.1"], "ScanFolders" : ["\a\b\c", "\d\e\f"] CommandLineOptionPrefix = "-/"
Then the resulting dumped value would be Dump = ["Foo", "Bat", "-GameFolder", "-RemoteIp", "10.0.0.1", "-ScanFolders", "\a\b\c", "-ScanFolders", "\d\e\f"]
AZStd::size_t AZ::CommandLine::GetNumSwitchValues | ( | AZStd::string_view | switchName | ) | const |
Get the number of values for the given switch.
const AZStd::string & AZ::CommandLine::GetSwitchValue | ( | AZStd::string_view | switchName | ) | const |
Get the actual value of a switch
switchName | The switch to search for |
const AZStd::string & AZ::CommandLine::GetSwitchValue | ( | AZStd::string_view | switchName, |
AZStd::size_t | index | ||
) | const |
Get the actual value of a switch
switchName | The switch to search for |
index | The 0-based index to retrieve the switch value for |
bool AZ::CommandLine::HasSwitch | ( | AZStd::string_view | switchName | ) | const |
Determines whether a switch is present in the command line
void AZ::CommandLine::Parse | ( | AZStd::span< const AZStd::string_view > | commandLine | ) |
Parses each element of the command line as parameter. Unlike the ARGC/ARGV version above, this function doesn't skip over the first parameter It allows for round trip conversion with the Dump() method
void AZ::CommandLine::Parse | ( | int | argc, |
char ** | argv | ||
) |
Construct a command line parser. It will load parameters from the given ARGC/ARGV parameters instead of process command line. Skips over the first parameter as it assumes it is the executable name