![]() |
CopperSpice API
2.0.0
|
The QCommandLineOption class defines a possible command-line option. More...
Public Methods | |
QCommandLineOption (const QCommandLineOption &other) | |
QCommandLineOption (const QString &name, const QString &description=QString (), const QString &valueName=QString (), const QString &defaultValue=QString ()) | |
QCommandLineOption (const QStringList &names, const QString &description=QString (), const QString &valueName=QString (), const QString &defaultValue=QString ()) | |
~QCommandLineOption () | |
QStringList | defaultValues () const |
QString | description () const |
QStringList | names () const |
QCommandLineOption & | operator= (const QCommandLineOption &other) |
QCommandLineOption & | operator= (QCommandLineOption &&other) |
void | setDefaultValue (const QString &defaultValue) |
void | setDefaultValues (const QStringList &defaultValues) |
void | setDescription (const QString &description) |
void | setValueName (const QString &name) |
void | swap (QCommandLineOption &other) |
QString | valueName () const |
The QCommandLineOption class defines a possible command line option.
This class is used to describe an option which can be passed on the command line. There are different ways of defining the same option and multiple aliases can be used. It is also used to describe how the option is used in your program. This may be a flag such as "-h" or require a value as in "-o file".
|
explicit |
Constructs a command line option object with the given arguments.
The name of the option is set to name. The name can be either short or long. If the name is one character in length, it is considered a short name. Option names must not be empty, must not start with a dash or a slash character, must not contain a =
and can not be repeated.
The description is set to description. It is customary to add a period at the end of the description. The valueName can be set if the option expects a value. The default value for the option is set to defaultValue.
|
explicit |
Constructs a command line option object with the given arguments. This overload allows setting multiple names for the option, for instance o
and output
.
The names of the option are set to names. The names can be either short or long. Any name in the list that is one character in length is a short name. Option names must not be empty, must not start with a dash or a slash character, must not contain a =
and can not be repeated.
The description is set to description. It is customary to add a period at the end of the description. In addition, the valueName can be set if the option expects a value. The default value for the option is set to defaultValue.
QCommandLineOption::QCommandLineOption | ( | const QCommandLineOption & | other | ) |
Constructs a QCommandLineOption object that is a copy of the QCommandLineOption object other.
QCommandLineOption::~QCommandLineOption | ( | ) |
Destroys the command line option object.
QStringList QCommandLineOption::defaultValues | ( | ) | const |
Returns the default values set for this option.
QString QCommandLineOption::description | ( | ) | const |
Returns the description set for this option.
QStringList QCommandLineOption::names | ( | ) | const |
Returns the names set for this option.
QCommandLineOption & QCommandLineOption::operator= | ( | const QCommandLineOption & | other | ) |
Copy assigns from other and returns a reference to this object.
|
inline |
Move assigns from other and returns a reference to this object.
void QCommandLineOption::setDefaultValue | ( | const QString & | defaultValue | ) |
Sets the default value used for this option to defaultValue. The default value is used if the user of the application does not specify the option on the command line.
void QCommandLineOption::setDefaultValues | ( | const QStringList & | defaultValues | ) |
Sets the list of default values used for this option to defaultValues. The default values are used if the user of the application does not specify the option on the command line.
void QCommandLineOption::setDescription | ( | const QString & | description | ) |
Sets the description used for this option to description. It is customary to add a "." at the end of the description.
The description is used by QCommandLineParser::showHelp().
void QCommandLineOption::setValueName | ( | const QString & | name | ) |
Sets the name of the expected value, for the documentation, to name. Options without a value assigned have a boolean-like behavior: either the user specifies –option or they do not.
Options with a value assigned need to set a name for the expected value, for the documentation of the option in the help output. An option with names o
and output
, and a value name of file
will appear as -o, –output <file>
.
Call QCommandLineParser::value() if you expect the option to be present only once, and QCommandLineParser::values() if you expect that option to be present multiple times.
|
inline |
Swaps option other with this option. This operation is very fast and never fails.
QString QCommandLineOption::valueName | ( | ) | const |
Returns the name of the expected value. If empty, the option does not take a value.