PySide6.QtCore.QCommandLineOption¶
- class QCommandLineOption¶
The
QCommandLineOption
class defines a possible command-line option. More…Synopsis¶
Methods¶
def
__init__()
def
defaultValues()
def
description()
def
flags()
def
names()
def
setDescription()
def
setFlags()
def
setValueName()
def
swap()
def
valueName()
Note
This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE
Detailed Description¶
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
This class is used to describe an option on the command line. It allows different ways of defining the same option with multiple aliases possible. It is also used to describe how the option is used - it may be a flag (e.g.
-v
) or take a value (e.g.-o file
).Examples:
verboseOption = QCommandLineOption("verbose", "Verbose mode. Prints out more information.") outputOption = QCommandLineOption(QStringList() << "o" << "output", "Write generated data into .", "file")
See also
- class Flag¶
Constant
Description
QCommandLineOption.HiddenFromHelp
(inherits
enum.Flag
) Hide this option in the user-visible help output. All options are visible by default. Setting this flag for a particular option makes it internal, i.e. not listed in the help output.QCommandLineOption.ShortOptionStyle
The option will always be understood as a short option, regardless of what was set by
setSingleDashWordOptionMode
. This allows flags such as-DDEFINE=VALUE
or-I/include/path
to be interpreted as short flags even when the parser is inParseAsLongOptions
mode.See also
- __init__(other)¶
- Parameters:
other –
QCommandLineOption
Constructs a
QCommandLineOption
object that is a copy of theQCommandLineOption
objectother
.See also
operator=()
- __init__(name)
- Parameters:
name – str
Constructs a command line option object with the name
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 cannot be repeated.- __init__(names)
- Parameters:
names – list of strings
Constructs a command line option object with the names
names
.This overload allows to set multiple names for the option, for instance
o
andoutput
.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 cannot be repeated.- __init__(name, description[, valueName=""[, defaultValue=""]])
- Parameters:
name – str
description – str
valueName – str
defaultValue – str
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
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 cannot be repeated.The description is set to
description
. It is customary to add a “.” at the end of the description.In addition, the
valueName
needs to be set if the option expects a value. The default value for the option is set todefaultValue
.In Qt versions before 5.4, this constructor was
explicit
. In Qt 5.4 and later, it no longer is and can be used for uniform initialization:parser = QCommandLineParser() parser.addOption({"verbose", "Verbose mode. Prints out more information."})
- __init__(names, description[, valueName=""[, defaultValue=""]])
- Parameters:
names – list of strings
description – str
valueName – str
defaultValue – str
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
Constructs a command line option object with the given arguments.
This overload allows to set multiple names for the option, for instance
o
andoutput
.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 cannot be repeated.The description is set to
description
. It is customary to add a “.” at the end of the description.In addition, the
valueName
needs to be set if the option expects a value. The default value for the option is set todefaultValue
.In Qt versions before 5.4, this constructor was
explicit
. In Qt 5.4 and later, it no longer is and can be used for uniform initialization:parser = QCommandLineParser() parser.addOption({{"o", "output"}, "Write generated data into <file>.", "file"})
- defaultValues()¶
- Return type:
list of strings
Returns the default values set for this option.
See also
- description()¶
- Return type:
str
Returns the description set for this option.
See also
Returns a set of flags that affect this command-line option.
See also
setFlags()
Flags
- names()¶
- Return type:
list of strings
Returns the names set for this option.
- setDefaultValue(defaultValue)¶
- Parameters:
defaultValue – str
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.
If
defaultValue
is empty, the option has no default values.See also
- setDefaultValues(defaultValues)¶
- Parameters:
defaultValues – list of strings
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.
See also
- setDescription(description)¶
- Parameters:
description – str
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
showHelp()
.See also
Set the set of flags that affect this command-line option to
flags
.See also
flags()
Flags
- setValueName(name)¶
- Parameters:
name – str
Sets the name of the expected value, for the documentation, to
valueName
.Options without a value assigned have a boolean-like behavior: either the user specifies –option or they don’t.
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
andoutput
, and a value name offile
will appear as-o, --output <file>
.Call
value()
if you expect the option to be present only once, andvalues()
if you expect that option to be present multiple times.See also
- swap(other)¶
- Parameters:
other –
QCommandLineOption
Swaps option
other
with this option. This operation is very fast and never fails.- valueName()¶
- Return type:
str
Returns the name of the expected value.
If empty, the option doesn’t take a value.
See also