JUCE  v5.4.1-191-g0ab5e696f
JUCE API
Looking for a senior C++ dev?
I'm looking for work. Hire me!
juce::ArgumentList Struct Reference

Holds a list of command-line arguments, and provides useful methods for searching and operating on them. More...

#include <juce_ConsoleApplication.h>

Collaboration diagram for juce::ArgumentList:

Classes

struct  Argument
 One of the arguments in an ArgumentList. More...
 

Public Member Functions

 ArgumentList (String executable, StringArray arguments)
 Creates an argument list for a given executable. More...
 
 ArgumentList (int argc, char *argv[])
 Parses a standard argv/argc pair to create an argument list. More...
 
 ArgumentList (const String &executable, const String &arguments)
 Tokenises a string containing all the arguments to create an argument list. More...
 
 ArgumentList (const ArgumentList &)=default
 
void checkMinNumArguments (int expectedMinNumberOfArgs) const
 Throws an error unless there are at least the given number of arguments. More...
 
bool containsOption (StringRef option) const
 Returns true if the given string matches one of the arguments. More...
 
void failIfOptionIsMissing (StringRef option) const
 Throws an error unless the given option is found in the argument list. More...
 
Argument getArgumentAfterOption (StringRef option) const
 Looks for the given argument and returns the one that follows it in the list. More...
 
File getExistingFileAfterOption (StringRef option) const
 Looks for a given argument and tries to parse the following argument as a file which must exist for this to succeed. More...
 
File getExistingFolderAfterOption (StringRef option) const
 Looks for a given argument and tries to parse the following argument as a folder which must exist for this to succeed. More...
 
File getFileAfterOption (StringRef option) const
 Looks for a given argument and tries to parse the following argument as a file. More...
 
int indexOfOption (StringRef option) const
 Returns the index of the given string if it matches one of the arguments, or -1 if it doesn't. More...
 
ArgumentListoperator= (const ArgumentList &)=default
 
Argument operator[] (int index) const
 Returns one of the arguments. More...
 
int size () const
 Returns the number of arguments in the list. More...
 

Public Attributes

Array< Argumentarguments
 The list of arguments (not including the name of the executable that was invoked). More...
 
String executableName
 The name or path of the executable that was invoked, as it was specified on the command-line. More...
 

Detailed Description

Holds a list of command-line arguments, and provides useful methods for searching and operating on them.

You can create an ArgumentList manually, or give it some argv/argc values from a main() function to parse.

See also
ConsoleApplication

Constructor & Destructor Documentation

◆ ArgumentList() [1/4]

juce::ArgumentList::ArgumentList ( String  executable,
StringArray  arguments 
)

Creates an argument list for a given executable.

◆ ArgumentList() [2/4]

juce::ArgumentList::ArgumentList ( int  argc,
char *  argv[] 
)

Parses a standard argv/argc pair to create an argument list.

◆ ArgumentList() [3/4]

juce::ArgumentList::ArgumentList ( const String executable,
const String arguments 
)

Tokenises a string containing all the arguments to create an argument list.

◆ ArgumentList() [4/4]

juce::ArgumentList::ArgumentList ( const ArgumentList )
default

Member Function Documentation

◆ checkMinNumArguments()

void juce::ArgumentList::checkMinNumArguments ( int  expectedMinNumberOfArgs) const

Throws an error unless there are at least the given number of arguments.

◆ containsOption()

bool juce::ArgumentList::containsOption ( StringRef  option) const

Returns true if the given string matches one of the arguments.

The option can also be a list of different versions separated by pipes, e.g. "--help|-h"

◆ failIfOptionIsMissing()

void juce::ArgumentList::failIfOptionIsMissing ( StringRef  option) const

Throws an error unless the given option is found in the argument list.

◆ getArgumentAfterOption()

Argument juce::ArgumentList::getArgumentAfterOption ( StringRef  option) const

Looks for the given argument and returns the one that follows it in the list.

The option can also be a list of different versions separated by pipes, e.g. "--help|-h" If the argument isn't found, this returns an empty string.

◆ getExistingFileAfterOption()

File juce::ArgumentList::getExistingFileAfterOption ( StringRef  option) const

Looks for a given argument and tries to parse the following argument as a file which must exist for this to succeed.

The option can also be a list of different versions separated by pipes, e.g. "--help|-h" If the option isn't found, or if the next argument isn't a filename, or if the file doesn't exist, or if it's a folder rather than a file, then it will throw a suitable error.

◆ getExistingFolderAfterOption()

File juce::ArgumentList::getExistingFolderAfterOption ( StringRef  option) const

Looks for a given argument and tries to parse the following argument as a folder which must exist for this to succeed.

The option can also be a list of different versions separated by pipes, e.g. "--help|-h" If the option isn't found, or if the next argument isn't a filename, or if it doesn't point to a folder, then it will throw a suitable error.

◆ getFileAfterOption()

File juce::ArgumentList::getFileAfterOption ( StringRef  option) const

Looks for a given argument and tries to parse the following argument as a file.

The option can also be a list of different versions separated by pipes, e.g. "--help|-h" If the option isn't found, or if the next argument isn't a filename, it will throw an error.

◆ indexOfOption()

int juce::ArgumentList::indexOfOption ( StringRef  option) const

Returns the index of the given string if it matches one of the arguments, or -1 if it doesn't.

The option can also be a list of different versions separated by pipes, e.g. "--help|-h"

◆ operator=()

ArgumentList& juce::ArgumentList::operator= ( const ArgumentList )
default

◆ operator[]()

Argument juce::ArgumentList::operator[] ( int  index) const

Returns one of the arguments.

◆ size()

int juce::ArgumentList::size ( ) const

Returns the number of arguments in the list.

Member Data Documentation

◆ arguments

Array<Argument> juce::ArgumentList::arguments

The list of arguments (not including the name of the executable that was invoked).

◆ executableName

String juce::ArgumentList::executableName

The name or path of the executable that was invoked, as it was specified on the command-line.


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