• Skip to content
  • Skip to link menu
KDE 4.6 API Reference
  • KDE API Reference
  • kdelibs
  • KDE Home
  • Contact Us
 

KDECore

Public Member Functions

KCmdLineOptions Class Reference

Class that holds command line options. More...

#include <kcmdlineargs.h>

List of all members.

Public Member Functions

 KCmdLineOptions ()
 KCmdLineOptions (const KCmdLineOptions &options)
 ~KCmdLineOptions ()
KCmdLineOptions & add (const QByteArray &name, const KLocalizedString &description=KLocalizedString(), const QByteArray &defaultValue=QByteArray())
KCmdLineOptions & add (const KCmdLineOptions &options)
KCmdLineOptions & operator= (const KCmdLineOptions &options)

Detailed Description

Class that holds command line options.

This class is intended to be used with the KCmdLineArgs class, which provides convenient and powerful command line argument parsing and handling functionality.

See also:
KCmdLineArgs for additional usage information

Definition at line 48 of file kcmdlineargs.h.


Constructor & Destructor Documentation

KCmdLineOptions::KCmdLineOptions ( )

Constructor.

Definition at line 121 of file kcmdlineargs.cpp.

KCmdLineOptions::KCmdLineOptions ( const KCmdLineOptions &  options)

Copy constructor.

Definition at line 130 of file kcmdlineargs.cpp.

KCmdLineOptions::~KCmdLineOptions ( )

Destructor.

Definition at line 125 of file kcmdlineargs.cpp.


Member Function Documentation

KCmdLineOptions & KCmdLineOptions::add ( const QByteArray &  name,
const KLocalizedString &  description = KLocalizedString(),
const QByteArray &  defaultValue = QByteArray() 
)

Add command line option, by providing its name, description, and possibly a default value.

These will print out when myapp --help is called on the command line.

Note that a long option can only have one short (single character) alias

Since:
4.6 Note that the following does not apply to options that begin with "no" and expect a parameter, like "nooption4" in the example bellow.

Note that if the option name begin with "no" that you will need to test for the name without the "no" and the result will be the inverse of what is specified. i.e. if "nofoo" is the name of the option and myapp --nofoo is called:

 KCmdLineArgs::parsedArgs()->isSet("foo"); // false

Here are some more examples showing various features:

  KCmdLineOptions options;
  options.add("a", ki18n("A short binary option"));
  options.add("b <file>", ki18n("A short option which takes an argument"));
  options.add("c <speed>", ki18n("As above but with a default value"), "9600");
  options.add("option1", ki18n("A long binary option, off by default"));
  options.add("nooption2", ki18n("A long binary option, on by default"));
  options.add(":", ki18n("Extra options:"));
  options.add("option3 <file>", ki18n("A long option which takes an argument"));
  options.add("nooption4 <speed>", ki18n("A long option which takes an argument, defaulting to 9600"), "9600");
  options.add("d").add("option5", ki18n("A long option which has a short option as alias"));
  options.add("e").add("nooption6", ki18n("Another long option with an alias"));
  options.add("f").add("option7 <speed>", ki18n("'--option7 speed' is the same as '-f speed'"));
  options.add("!option8 <cmd>", ki18n("All options following this one will be treated as arguments"));
  options.add("+file", ki18n("A required argument 'file'"));
  options.add("+[arg1]", ki18n("An optional argument 'arg1'"));
  options.add("!+command", ki18n("A required argument 'command', that can contain multiple words, even starting with '-'"));
  options.add("", ki18n("Additional help text not associated with any particular option"));
Parameters:
nameoption name
descriptionoption description, made available for translation; can be left off
defaultValuedefault option value, when the value is not specified on the command line; can be left off

Definition at line 143 of file kcmdlineargs.cpp.

KCmdLineOptions & KCmdLineOptions::add ( const KCmdLineOptions &  options)

Add all options from another KCmdLineOptions object.

Parameters:
optionsoptions to add

Definition at line 153 of file kcmdlineargs.cpp.

KCmdLineOptions & KCmdLineOptions::operator= ( const KCmdLineOptions &  options)

Assignment operator.

Definition at line 135 of file kcmdlineargs.cpp.


The documentation for this class was generated from the following files:
  • kcmdlineargs.h
  • kcmdlineargs.cpp

KDECore

Skip menu "KDECore"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.7.3
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal