PythonQt.QtCore.QCommandLineParser · declarations 001
Back to PythonQt.QtCore.QCommandLineParser
OptionsAfterPositionalArgumentsMode
instance-attribute
OptionsAfterPositionalArgumentsMode: type
int([x]) -> integer int(x, base=10) -> integer
Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.int(). For floating point numbers, this truncates towards zero.
If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by '+' or '-' and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer literal.
int('0b100', base=0) 4
ParseAsCompactedShortOptions
instance-attribute
ParseAsCompactedShortOptions: Any
ParseAsLongOptions
instance-attribute
ParseAsLongOptions: Any
ParseAsOptions
instance-attribute
ParseAsOptions: Any
ParseAsPositionalArguments
instance-attribute
ParseAsPositionalArguments: Any
SingleDashWordOptionMode
instance-attribute
SingleDashWordOptionMode: type
int([x]) -> integer int(x, base=10) -> integer
Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.int(). For floating point numbers, this truncates towards zero.
If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by '+' or '-' and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer literal.
int('0b100', base=0) 4
addHelpOption
addHelpOption() -> Any
X.addHelpOption() -> PythonQt.QtCore.QCommandLineOption
Supplemental documentation: Qt 5 reference:
QCommandLineOption QCommandLineParser::addHelpOption()
Adds the help option (-h, --help and -? on Windows) as well as an option
--help-all to include Qt-specific options in the output.
These options are handled automatically by QCommandLineParser.
Remember to use setApplicationDescription to set the application description, which will be displayed when this option is used.
Example:
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
QCoreApplication::setApplicationName("my-copy-program");
QCoreApplication::setApplicationVersion("1.0");
QCommandLineParser parser;
parser.setApplicationDescription("Test helper");
parser.addHelpOption();
parser.addVersionOption();
parser.addPositionalArgument("source", QCoreApplication::translate("main", "Source file to copy."));
parser.addPositionalArgument("destination", QCoreApplication::translate("main", "Destination directory."));
// A boolean option with a single name (-p)
QCommandLineOption showProgressOption("p", QCoreApplication::translate("main", "Show progress during copy"));
parser.addOption(showProgressOption);
// A boolean option with multiple names (-f, --force)
QCommandLineOption forceOption(QStringList() << "f" << "force",
QCoreApplication::translate("main", "Overwrite existing files."));
parser.addOption(forceOption);
// An option with a value
QCommandLineOption targetDirectoryOption(QStringList() << "t" << "target-directory",
QCoreApplication::translate("main", "Copy all source files into <directory>."),
QCoreApplication::translate("main", "directory"));
parser.addOption(targetDirectoryOption);
// Process the actual command line arguments given by the user
parser.process(app);
const QStringList args = parser.positionalArguments();
// source is args.at(0), destination is args.at(1)
bool showProgress = parser.isSet(showProgressOption);
bool force = parser.isSet(forceOption);
QString targetDir = parser.value(targetDirectoryOption);
// ...
}
Returns the option instance, which can be used to call isSet().
Upstream PySide2 reference signatures (binding differences may apply):
addHelpOption(self) -> PySide2.QtCore.QCommandLineOption
Source: https://doc.qt.io/archives/qt-5.15/qcommandlineparser.html#addHelpOption
addOption
addOption(commandLineOption: Any) -> bool
X.addOption(commandLineOption) -> bool
Supplemental documentation: Qt 5 reference:
bool QCommandLineParser::addOption(const QCommandLineOption \&option)
Adds the option option to look for while parsing.
Returns true if adding the option was successful; otherwise returns false.
Adding the option fails if there is no name attached to the option, or the option has a name that clashes with an option name added before.
Upstream PySide2 reference signatures (binding differences may apply):
addOption(self, commandLineOption: PySide2.QtCore.QCommandLineOption) -> bool
Source: https://doc.qt.io/archives/qt-5.15/qcommandlineparser.html#addOption
addOptions
addOptions(options: Any) -> bool
X.addOptions(options) -> bool
Supplemental documentation: Qt 5 reference:
bool QCommandLineParser::addOptions(const QList\<QCommandLineOption> \&options)
Adds the options to look for while parsing. The options are specified by the parameter options.
Returns true if adding all of the options was successful; otherwise returns false.
See the documentation for addOption() for when this function may fail.
This function was introduced in Qt 5.4.
Upstream PySide2 reference signatures (binding differences may apply):
addOptions(self, options: typing.Sequence[PySide2.QtCore.QCommandLineOption]) -> bool
Source: https://doc.qt.io/archives/qt-5.15/qcommandlineparser.html#addOptions
addPositionalArgument
addPositionalArgument(name: str, description: str, syntax: str) -> None
X.addPositionalArgument(name, description, syntax)
Supplemental documentation: Qt 5 reference:
void QCommandLineParser::addPositionalArgument(const QString \&name, const QString \&description, const QString \&syntax \= QString())
Defines an additional argument to the application, for the benefit of the help text.
The argument name and description will appear under the Arguments: section of the
help. If syntax is specified, it will be appended to the Usage line, otherwise the
name will be appended.
Example:
// Usage: image-editor file
//
// Arguments:
// file The file to open.
parser.addPositionalArgument("file", QCoreApplication::translate("main", "The file to open."));
// Usage: web-browser [urls...]
//
// Arguments:
// urls URLs to open, optionally.
parser.addPositionalArgument("urls", QCoreApplication::translate("main", "URLs to open, optionally."), "[urls...]");
// Usage: cp source destination
//
// Arguments:
// source Source file to copy.
// destination Destination directory.
parser.addPositionalArgument("source", QCoreApplication::translate("main", "Source file to copy."));
parser.addPositionalArgument("destination", QCoreApplication::translate("main", "Destination directory."));
See also addHelpOption() and helpText().
Upstream PySide2 reference signatures (binding differences may apply):
addPositionalArgument(self, name: str, description: str, syntax: str=...) -> None
Source: https://doc.qt.io/archives/qt-5.15/qcommandlineparser.html#addPositionalArgument
addVersionOption
addVersionOption() -> Any
X.addVersionOption() -> PythonQt.QtCore.QCommandLineOption
Supplemental documentation: Qt 5 reference:
QCommandLineOption QCommandLineParser::addVersionOption()
Adds the -v / --version option, which displays the version string of the
application.
This option is handled automatically by QCommandLineParser.
You can set the actual version string by using QCoreApplication::setApplicationVersion().
Returns the option instance, which can be used to call isSet().
Upstream PySide2 reference signatures (binding differences may apply):
addVersionOption(self) -> PySide2.QtCore.QCommandLineOption
Source: https://doc.qt.io/archives/qt-5.15/qcommandlineparser.html#addVersionOption
applicationDescription
applicationDescription() -> str
X.applicationDescription() -> str
Supplemental documentation: Qt 5 reference:
QString QCommandLineParser::applicationDescription() const
Returns the application description set in setApplicationDescription().
See also setApplicationDescription().
Upstream PySide2 reference signatures (binding differences may apply):
applicationDescription(self) -> str
Source: https://doc.qt.io/archives/qt-5.15/qcommandlineparser.html#applicationDescription
clearPositionalArguments
clearPositionalArguments() -> None
X.clearPositionalArguments()
Supplemental documentation: Qt 5 reference:
void QCommandLineParser::clearPositionalArguments()
Clears the definitions of additional arguments from the help text.
This is only needed for the special case of tools which support multiple commands with different options. Once the actual command has been identified, the options for this command can be defined, and the help text for the command can be adjusted accordingly.
Example:
QCoreApplication app(argc, argv);
QCommandLineParser parser;
parser.addPositionalArgument("command", "The command to execute.");
// Call parse() to find out the positional arguments.
parser.parse(QCoreApplication::arguments());
const QStringList args = parser.positionalArguments();
const QString command = args.isEmpty() ? QString() : args.first();
if (command == "resize") {
parser.clearPositionalArguments();
parser.addPositionalArgument("resize", "Resize the object to a new size.", "resize [resize_options]");
parser.addOption(QCommandLineOption("size", "New size.", "new_size"));
parser.process(app);
// ...
}
/*
This code results in context-dependent help:
$ tool --help
Usage: tool command
Arguments:
command The command to execute.
$ tool resize --help
Usage: tool resize [resize_options]
Options:
--size <size> New size.
Arguments:
resize Resize the object to a new size.
*/
Upstream PySide2 reference signatures (binding differences may apply):
clearPositionalArguments(self) -> None
Source: https://doc.qt.io/archives/qt-5.15/qcommandlineparser.html#clearPositionalArguments
errorText
errorText() -> str
X.errorText() -> str
Supplemental documentation: Qt 5 reference:
QString QCommandLineParser::errorText() const
Returns a translated error text for the user. This should only be called when
parse() returns
false.
Upstream PySide2 reference signatures (binding differences may apply):
errorText(self) -> str
Source: https://doc.qt.io/archives/qt-5.15/qcommandlineparser.html#errorText
helpText
helpText() -> str
X.helpText() -> str
Supplemental documentation: Qt 5 reference:
QString QCommandLineParser::helpText() const
Returns a string containing the complete help information.
See also showHelp().
Upstream PySide2 reference signatures (binding differences may apply):
helpText(self) -> str
Source: https://doc.qt.io/archives/qt-5.15/qcommandlineparser.html#helpText
isSet
isSet(option: Any) -> bool
X.isSet(option) -> bool
Supplemental documentation: Qt 5 reference:
bool QCommandLineParser::isSet(const QString \&name) const
Checks whether the option name was passed to the application.
Returns true if the option name was set, false otherwise.
The name provided can be any long or short name of any option that was added with
addOption(). All the options names are treated as being equivalent. If the name is not
recognized or that option was not present, false is returned.
Example:
bool verbose = parser.isSet("verbose");
bool QCommandLineParser::isSet(const QCommandLineOption \&option) const
This is an overloaded function.
Checks whether the option was passed to the application.
Returns true if the option was set, false otherwise.
This is the recommended way to check for options with no values.
Example:
QCoreApplication app(argc, argv);
QCommandLineParser parser;
QCommandLineOption verboseOption("verbose");
parser.addOption(verboseOption);
parser.process(app);
bool verbose = parser.isSet(verboseOption);
Upstream PySide2 reference signatures (binding differences may apply):
isSet(self, name: str) -> bool
isSet(self, option: PySide2.QtCore.QCommandLineOption) -> bool
Source: https://doc.qt.io/archives/qt-5.15/qcommandlineparser.html#isSet
optionNames
optionNames() -> tuple
X.optionNames() -> tuple
Supplemental documentation: Qt 5 reference:
QStringList QCommandLineParser::optionNames() const
Returns a list of option names that were found.
This returns a list of all the recognized option names found by the parser, in the order in which they were found. For any long options that were in the form {--option\=value}, the value part will have been dropped.
The names in this list do not include the preceding dash characters. Names may appear more than once in this list if they were encountered more than once by the parser.
Any entry in the list can be used with value() or with values() to get any relevant
option values.
Upstream PySide2 reference signatures (binding differences may apply):
optionNames(self) -> typing.List[str]
Source: https://doc.qt.io/archives/qt-5.15/qcommandlineparser.html#optionNames
parse
parse(arguments: Any) -> bool
X.parse(arguments) -> bool
Supplemental documentation: Qt 5 reference:
bool QCommandLineParser::parse(const QStringList \&arguments)
Parses the command line arguments.
Most programs don't need to call this, a simple call to process() is enough.
parse() is more low-level, and only does the parsing. The application will have to take
care of the error handling, using
errorText() if
parse() returns false. This can be useful for instance to show a graphical error
message in graphical programs.
Calling parse() instead of process() can also be useful in order to ignore unknown options temporarily, because more option definitions will be provided later on (depending on one of the arguments), before calling process().
Don't forget that arguments must start with the name of the executable (ignored, though).
Returns false in case of a parse error (unknown option or missing value); returns
true otherwise.
See also process().
Upstream PySide2 reference signatures (binding differences may apply):
parse(self, arguments: typing.Sequence[str]) -> bool
Source: https://doc.qt.io/archives/qt-5.15/qcommandlineparser.html#parse
positionalArguments
positionalArguments() -> tuple
X.positionalArguments() -> tuple
Supplemental documentation: Qt 5 reference:
QStringList QCommandLineParser::positionalArguments() const
Returns a list of positional arguments.
These are all of the arguments that were not recognized as part of an option.
Upstream PySide2 reference signatures (binding differences may apply):
positionalArguments(self) -> typing.List[str]
Source: https://doc.qt.io/archives/qt-5.15/qcommandlineparser.html#positionalArguments
process
process(app: Any) -> None
X.process(app)
Supplemental documentation: Qt 5 reference:
void QCommandLineParser::process(const QStringList \&arguments)
Processes the command line arguments.
In addition to parsing the options (like parse()), this function also handles the builtin options and handles errors.
The builtin options are --version if
addVersionOption
was called and --help / --help-all if
addHelpOption
was called.
When invoking one of these options, or when an error happens (for instance an unknown option was passed), the current process will then stop, using the exit() function.
See also QCoreApplication::arguments() and parse().
void QCommandLineParser::process(const QCoreApplication \&app)
This is an overloaded function.
The command line is obtained from the QCoreApplication instance app.
Upstream PySide2 reference signatures (binding differences may apply):
process(self, app: PySide2.QtCore.QCoreApplication) -> None
process(self, arguments: typing.Sequence[str]) -> None
Source: https://doc.qt.io/archives/qt-5.15/qcommandlineparser.html#process
setApplicationDescription
setApplicationDescription(description: str) -> None
X.setApplicationDescription(description)
Supplemental documentation: Qt 5 reference:
void QCommandLineParser::setApplicationDescription(const QString \&description)
Sets the application description shown by helpText().
See also applicationDescription().
Upstream PySide2 reference signatures (binding differences may apply):
setApplicationDescription(self, description: str) -> None
Source: https://doc.qt.io/archives/qt-5.15/qcommandlineparser.html#setApplicationDescription
setOptionsAfterPositionalArgumentsMode
setOptionsAfterPositionalArgumentsMode(mode: Any) -> None
X.setOptionsAfterPositionalArgumentsMode(mode)
Supplemental documentation: Qt 5 reference:
void QCommandLineParser::setOptionsAfterPositionalArgumentsMode(QCommandLineParser::OptionsAfterPositionalArgumentsMode parsingMode)
Sets the parsing mode to parsingMode. This must be called before process() or parse().
This function was introduced in Qt 5.6.
Upstream PySide2 reference signatures (binding differences may apply):
setOptionsAfterPositionalArgumentsMode(self, mode: PySide2.QtCore.QCommandLineParser.OptionsAfterPositionalArgumentsMode) -> None
Source: https://doc.qt.io/archives/qt-5.15/qcommandlineparser.html#setOptionsAfterPositionalArgumentsMode
setSingleDashWordOptionMode
setSingleDashWordOptionMode(parsingMode: Any) -> None
X.setSingleDashWordOptionMode(parsingMode)
Supplemental documentation: Qt 5 reference:
void QCommandLineParser::setSingleDashWordOptionMode(QCommandLineParser::SingleDashWordOptionMode singleDashWordOptionMode)
Sets the parsing mode to singleDashWordOptionMode. This must be called before process() or parse().
Upstream PySide2 reference signatures (binding differences may apply):
setSingleDashWordOptionMode(self, parsingMode: PySide2.QtCore.QCommandLineParser.SingleDashWordOptionMode) -> None
Source: https://doc.qt.io/archives/qt-5.15/qcommandlineparser.html#setSingleDashWordOptionMode
showHelp
showHelp(exitCode: int) -> None
X.showHelp(exitCode)
Supplemental documentation: Qt 5 reference:
void QCommandLineParser::showHelp(int exitCode \= 0)
Displays the help information, and exits the application. This is automatically triggered by the --help option, but can also be used to display the help when the user is not invoking the application correctly. The exit code is set to exitCode. It should be set to 0 if the user requested to see the help, and to any other value in case of an error.
See also helpText().
Upstream PySide2 reference signatures (binding differences may apply):
showHelp(self, exitCode: int=...) -> None
Source: https://doc.qt.io/archives/qt-5.15/qcommandlineparser.html#showHelp
showVersion
showVersion() -> None
X.showVersion()
Supplemental documentation: Qt 5 reference:
void QCommandLineParser::showVersion()
Displays the version information from QCoreApplication::applicationVersion(), and exits the application. This is automatically triggered by the --version option, but can also be used to display the version when not using process(). The exit code is set to EXIT_SUCCESS (0).
This function was introduced in Qt 5.4.
See also addVersionOption().
Upstream PySide2 reference signatures (binding differences may apply):
showVersion(self) -> None
Source: https://doc.qt.io/archives/qt-5.15/qcommandlineparser.html#showVersion
tr
tr(sourceText: Any, disambiguation: Any, n: Any) -> str
X.tr(sourceText, disambiguation, n) -> str
trUtf8
trUtf8(sourceText: Any, disambiguation: Any, n: Any) -> str
X.trUtf8(sourceText, disambiguation, n) -> str
unknownOptionNames
unknownOptionNames() -> tuple
X.unknownOptionNames() -> tuple
Supplemental documentation: Qt 5 reference:
QStringList QCommandLineParser::unknownOptionNames() const
Returns a list of unknown option names.
This list will include both long an short name options that were not recognized. For any long options that were in the form {--option\=value}, the value part will have been dropped and only the long name is added.
The names in this list do not include the preceding dash characters. Names may appear more than once in this list if they were encountered more than once by the parser.
See also optionNames().
Upstream PySide2 reference signatures (binding differences may apply):
unknownOptionNames(self) -> typing.List[str]
Source: https://doc.qt.io/archives/qt-5.15/qcommandlineparser.html#unknownOptionNames
value
value(option: Any) -> str
X.value(option) -> str
Supplemental documentation: Qt 5 reference:
QString QCommandLineParser::value(const QString \&optionName) const
Returns the option value found for the given option name optionName, or an empty string if not found.
The name provided can be any long or short name of any option that was added with
addOption(). All the option names are treated as being equivalent. If the name is not
recognized or that option was not present, an empty string is returned.
For options found by the parser, the last value found for that option is returned. If the option wasn't specified on the command line, the default value is returned.
An empty string is returned if the option does not take a value.
See also values(), QCommandLineOption::setDefaultValue(), and QCommandLineOption::setDefaultValues().
QString QCommandLineParser::value(const QCommandLineOption \&option) const
This is an overloaded function.
Returns the option value found for the given option, or an empty string if not found.
For options found by the parser, the last value found for that option is returned. If the option wasn't specified on the command line, the default value is returned.
An empty string is returned if the option does not take a value.
See also values(), QCommandLineOption::setDefaultValue(), and QCommandLineOption::setDefaultValues().
Upstream PySide2 reference signatures (binding differences may apply):
value(self, name: str) -> str
value(self, option: PySide2.QtCore.QCommandLineOption) -> str
Source: https://doc.qt.io/archives/qt-5.15/qcommandlineparser.html#value
values
values(option: Any) -> tuple
X.values(option) -> tuple
Supplemental documentation: Qt 5 reference:
QStringList QCommandLineParser::values(const QString \&optionName) const
Returns a list of option values found for the given option name optionName, or an empty list if not found.
The name provided can be any long or short name of any option that was added with
addOption(). All the options names are treated as being equivalent. If the name is not
recognized or that option was not present, an empty list is returned.
For options found by the parser, the list will contain an entry for each time the option was encountered by the parser. If the option wasn't specified on the command line, the default values are returned.
An empty list is returned if the option does not take a value.
See also value(), QCommandLineOption::setDefaultValue(), and QCommandLineOption::setDefaultValues().
QStringList QCommandLineParser::values(const QCommandLineOption \&option) const
This is an overloaded function.
Returns a list of option values found for the given option, or an empty list if not found.
For options found by the parser, the list will contain an entry for each time the option was encountered by the parser. If the option wasn't specified on the command line, the default values are returned.
An empty list is returned if the option does not take a value.
See also value(), QCommandLineOption::setDefaultValue(), and QCommandLineOption::setDefaultValues().
Upstream PySide2 reference signatures (binding differences may apply):
values(self, name: str) -> typing.List[str]
values(self, option: PySide2.QtCore.QCommandLineOption) -> typing.List[str]
Source: https://doc.qt.io/archives/qt-5.15/qcommandlineparser.html#values