class KCmdLineArgs |
|
|
A class for command-line argument handling. KCmdLineArgs provides simple access to the command-line arguments for an application. It takes into account Qt-specific options, KDE-specific options and application specific options. This class is used in %main() via the static method init(). A typical %KDE application using %KCmdLineArgs should look like this:
int main(int argc, char *argv[]) { // Initialize command line args KCmdLineArgs.init(argc, argv, appName, programName, version, description); The options that an application supports are configured using the KCmdLineOptions class. An example is shown below:
KCmdLineOptions options; options.add("a", ki18n("A short binary option")); options.add("b \ |
|
Internal Constructor. |
|
Returns the KAboutData for consumption by KComponentData |
|
Add options to your application. You must make sure that all possible options have been added before any class uses the command line arguments. The list of options should look like this:
KCmdLineOptions options; options.add("option1 \
KCmdLineArgs *args = KCmdLineArgs.parsedArgs(); if (args->count() == 0) KCmdLineArgs.usage(i18n("No file specified")); In BNF: cmd = myapp [options] file options = (option)* |
|
add standard Qt/KDE command-line args |
|
|
|
Get the appname according to argv[0]. Returns the name of the application
|
|
Read out an argument.
n - The argument to read. 0 is the first argument. count()-1 is the last argument. Returns n-th argument |
|
Clear all options and arguments. |
|
Read the number of arguments that aren't options (but, for example, filenames). Returns The number of arguments that aren't options |
|
Get the CWD (Current Working Directory) associated with the current command line arguments. Typically this is needed in KUniqueApplication.newInstance() since the CWD of the process may be different from the CWD where the user started a second instance. Returns the current working directory
|
|
Enable i18n to be able to print a translated error message. N.B.: This function leaks memory, therefore you are expected to exit afterwards (e.g., by calling usage()).
|
|
Read out a string option. The option must have a corresponding KCmdLineOptions entry of the form: options.add("option \You cannot test for the presence of an alias - you must always test for the full option.
option - The name of the option without '-'. Returns The value of the option. If the option was not present on the command line the default is returned. If the option was present more than once, the value of the last occurrence is used. |
|
Read out all occurrences of a string option. The option must have a corresponding KCmdLineOptions entry of the form: options.add("option \You cannot test for the presence of an alias - you must always test for the full option.
option - The name of the option, without '-' or '-no'. Returns A list of all option values. If no option was present on the command line, an empty list is returned. |
|
|
|
Initialize Class This function should be called as the very first thing in your application. This method will rarely be used, since it doesn't provide any argument parsing. It does provide access to the KAboutData information. This method is exactly the same as calling init(0,0, const KAboutData *about, CmdLineArgNone).
about - the about data. See also KAboutData |
|
Read out a boolean option or check for the presence of string option.
option - The name of the option without '-' or '-no'. Returns The value of the option. It will be true if the option was specifically turned on in the command line, or if the option is turned on by default (in the KCmdLineOptions list) and was not specifically turned off in the command line. Equivalently, it will be false if the option was specifically turned off in the command line, or if the option is turned off by default (in the KCmdLineOptions list) and was not specifically turned on in the command line. |
|
|
|
Load arguments from a stream. |
|
Used by url(). Made public for apps that don't use KCmdLineArgs urlArg - the argument Returns the url. |
|
Access parsed arguments. This function returns all command line arguments that your code handles. If unknown command-line arguments are encountered the program is aborted and usage information is shown.
id - The name of the options you are interested in, can be empty. |
|
Returns the number of arguments returned by qtArgv() See also qtArgv |
|
Returns command line options for consumption by Qt after parsing them in a way that is consistent with KDE's general command line handling. In particular this ensures |
|
Reset all option definitions, i.e. cancel all addCmdLineOptions calls. Note that KApplication's options are removed too, you might want to call KApplication.addCmdLineOptions if you want them back. You usually don't want to call this method. |
|
Made public for apps that don't use KCmdLineArgs To be done before makeURL, to set the current working directory in case makeURL needs it. cwd - the new working directory |
|
Read out an argument representing a URL. The argument can be
n - The argument to read. 0 is the first argument. count()-1 is the last argument. Returns a URL representing the n'th argument. |
|
Print the usage help to stdout and exit.
id - if empty, print all options. If id is set, only print the option specified by id. The id is the value set by addCmdLineOptions().
|
|
Print an error to stderr and the usage help to stdout and exit. error - the error to print
|
|
CmdLineArgQt | - | ||
CmdLineArgKDE | - | ||
CmdLineArgsMask | - | ||
CmdLineArgNone | - | ||
Reserved | - |