LibEngsas
Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
ECmdLineArgs Class Reference

Class to handle command line arguments and options. More...

#include <ecmdlineargs.h>

Public Member Functions

 ECmdLineArgs (EPart *part=NULL)
virtual ~ECmdLineArgs ()
bool init (int argc, char **argv)
 Instantiate the given options.
void add (const QByteArray &name, const QByteArray &alias=QByteArray(), const QString &description=QString(), const QByteArray &defaultValue=QByteArray())
 Add a new command line option to the list.
void add (ECmdLineOption *option)
 Adds an existent ECmdLineOption to the option list.
bool isSet (const QByteArray &option) const
 Checks wether the option is set.
QString getOption (const QByteArray &option) const
 Returns the value of option.
void addToKCmdLineOptions (KCmdLineOptions *option) const
 Adds all options to the given KCmdLineOptions option.

Protected Member Functions

virtual void showHelp () const
 Shows the help.
virtual void showVersion () const
 Shows version information of Qt, KDE, LibEngsas and the EPart.

Private Member Functions

ECmdLineOptionfindOption (const QByteArray &option) const
bool isSet (ECmdLineOption *option) const

Private Attributes

EngSaS::CmdLineOptions options
int argc
char ** argv
QPointer< EPartpart

Detailed Description

Class to handle command line arguments and options.

The class allows easy handling of command line arguments and options. To add a provided option or argument, use add(const QByteArray&, const QByteArray&, const QString&, const QByteArray&) or add(ECmdLineOption*). To get information about the added options, call init() first. Afterwards you can use isSet() to determine, if an option is set or getOption() to get back the result of the option.

Note
The options -v –version and -h –help are added and handled automatically.
// Create an ECmdLineArgs object to handle command line options.
// Register the given arguments from command line
args.init(argc, argv);
// register all possible options
// e.g. an optional option, which requires an argument
args.add("[user] <argument>", "u", "The user");
// e.g. an needed argument
args.add("+file", "", "A path to a file");
// than where you want to parse your options:
// check whether the option is given at the command line
if(args.isSet("user")
// retrieve the argument of the option
QString username = args.getOption("user");
See Also
ECmdLineOption

Constructor & Destructor Documentation

ECmdLineArgs::ECmdLineArgs ( EPart part = NULL)

Specify an EPart with part, to let showHelp() and showVersion() display the extended help of the part.

+ Here is the call graph for this function:

ECmdLineArgs::~ECmdLineArgs ( )
virtual

Member Function Documentation

void ECmdLineArgs::add ( const QByteArray &  name,
const QByteArray &  alias = QByteArray(),
const QString &  description = QString(),
const QByteArray &  defaultValue = QByteArray() 
)

Add a new command line option to the list.

This function creates a new ECmdLineOption object with the specified content. To add an existent ECmdLineOption use add(ECmdLineOption*).

+ Here is the caller graph for this function:

void ECmdLineArgs::add ( ECmdLineOption option)

Adds an existent ECmdLineOption to the option list.

To create a new option, use add(const QByteArray&, const QByteArray&, const QString&, const QByteArray&).

void ECmdLineArgs::addToKCmdLineOptions ( KCmdLineOptions *  option) const

Adds all options to the given KCmdLineOptions option.

If KDE is not enabled, this function does nothing.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ECmdLineOption * ECmdLineArgs::findOption ( const QByteArray &  option) const
private

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

QString ECmdLineArgs::getOption ( const QByteArray &  option) const

Returns the value of option.

It uses isSet() to set the value of option. option is the name of the option without any special characters like [], + or so (e.g. For "+[optionname] option should be optionname).

+ Here is the call graph for this function:

bool ECmdLineArgs::init ( int  argc,
char **  argv 
)

Instantiate the given options.

Returns
true if everything can be proceeded and false, if the application should exit. E.g. this can be the case, if the option -v or -h is chosen.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool ECmdLineArgs::isSet ( const QByteArray &  option) const

Checks wether the option is set.

If option is set, it also set's the value of the option to the first value of the occurence. option is the name of the option without any special characters like [], + or so (e.g. For "+[optionname] option should be optionname).

Todo:
improve handling of optional arguments and not optional arguments

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool ECmdLineArgs::isSet ( ECmdLineOption option) const
private

+ Here is the call graph for this function:

void ECmdLineArgs::showHelp ( ) const
protectedvirtual

Shows the help.

If you use ECmdLineArgs within your own application (not EPart based) you should subclass it and reimplement this function along with showVersion().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ECmdLineArgs::showVersion ( ) const
protectedvirtual

Shows version information of Qt, KDE, LibEngsas and the EPart.

If you use ECmdLineArgs within your own application (not EPart based) you should subclass it and reimplement this function along with showHelp().

Todo:
show LibEngsas version number

+ Here is the caller graph for this function:

Member Data Documentation

int ECmdLineArgs::argc
private
char** ECmdLineArgs::argv
private
EngSaS::CmdLineOptions ECmdLineArgs::options
private
QPointer<EPart> ECmdLineArgs::part
private

The documentation for this class was generated from the following files: