CrystalSpace

Public API Reference

csCommandLineHelper Class Reference

This class can be used to print the commandline help, eg when the '-help' option has been used. More...

#include <csutil/cmdhelp.h>

List of all members.

Public Member Functions

void AddCommandLineExample (const char *example)
 Add a commandline example to be printed in the list of usage examples (eg "myapp -l file.xml").
void AddCommandLineOption (const char *name, const char *description, csVariant value, size_t section=0)
 Add a commandline option to be described in the help text.
void AddCommandLineOption (csOptionDescription &description, csVariant &value, size_t section=0)
 Add a commandline option to be described in the help text.
size_t AddCommandLineSection (const char *name)
 Add a new section of options.
void PrintApplicationHelp (iObjectRegistry *registry, const char *command, const char *usage, const char *description) const
 Print to standard output all command options and usages of this application and its plugins.

Static Public Member Functions

static bool CheckHelp (iObjectRegistry *object_reg, iCommandLineParser *cmdline=0)
 Return whether or not the '-help' option has been given on the commandline.
static void Help (iObjectRegistry *object_reg, iCommandLineParser *cmdline=0)
 Print the plugin help on standard output.
static void PrintOption (const char *name, const char *description, const csVariant &value)
 Print an option on standard output.
static void PrintOption (const csOptionDescription &option, const csVariant &value)
 Print an option on standard output.
static void PrintTitle (const char *title, unsigned int level=0)
 Print a title on standard output.

Detailed Description

This class can be used to print the commandline help, eg when the '-help' option has been used.

A first functionality provided is the ability to print the options of all the currently loaded plugins, iff they implement iPluginConfig. Use Help() for this.

A more advanced usage is to print a help message for the whole application usage, not only for the available plugins. Use PrintApplicationHelp() for this.

To use PrintApplicationHelp(), you need to provide the command, usage, and description parameters which will contain the main description of your application and its usage. You can also add usage examples with AddCommandLineExample().

You can add specific options for your application through AddCommandLineOption(). If the list of your options is big, then you can structure these options in sections by using AddCommandLineSection().

When PrintApplicationHelp() is called, this tool will write to the standard output a help text of the following structure:

<description>

Usage: <usage>

Examples: <example>

Available options:

Specific options for <command>:
<list of options>

<section name>-specific options:
<list of options>

General options:
<list of CS general options>
Note:
This class requires the iPluginManager and iCommandLineParser to be in the object registry (alternatively you can provide them as parameters).

Definition at line 77 of file cmdhelp.h.


Member Function Documentation

void csCommandLineHelper::AddCommandLineExample ( const char *  example  ) 

Add a commandline example to be printed in the list of usage examples (eg "myapp -l file.xml").

void csCommandLineHelper::AddCommandLineOption ( const char *  name,
const char *  description,
csVariant  value,
size_t  section = 0 
)

Add a commandline option to be described in the help text.

Parameters:
name The name of the option, eg "debug"
description A user friendly description of the option, eg 'Enable output of debug information'.
section The index of the section of the option. A value of 0 means the default 'application' section.
void csCommandLineHelper::AddCommandLineOption ( csOptionDescription description,
csVariant value,
size_t  section = 0 
)

Add a commandline option to be described in the help text.

Parameters:
description The description of the option
section The index of the section of the option. A value of 0 means the default 'application' section.
size_t csCommandLineHelper::AddCommandLineSection ( const char *  name  ) 

Add a new section of options.

Return the index of this new section.

Note:
A default 'application' section with index 0 has already been created in the constructor of this object.
static bool csCommandLineHelper::CheckHelp ( iObjectRegistry object_reg,
iCommandLineParser cmdline = 0 
) [static]

Return whether or not the '-help' option has been given on the commandline.

If the commandline parser is not given then the default commandline parser from the registry will be used.

static void csCommandLineHelper::Help ( iObjectRegistry object_reg,
iCommandLineParser cmdline = 0 
) [static]

Print the plugin help on standard output.

This function will first send a broadcast message of type csevCommandLineHelp, then it will check all loaded plugins and print their options if they implement iPluginConfig.

If the commandline parser is not given then the default commandline parser from the registry will be used.

void csCommandLineHelper::PrintApplicationHelp ( iObjectRegistry registry,
const char *  command,
const char *  usage,
const char *  description 
) const

Print to standard output all command options and usages of this application and its plugins.

Parameters:
registry Main object registry
command Name of the executable (eg "myapp").
usage Syntax to launch the executable (eg "myapp <OPTIONS> filename").
description User friendly description of the application.
static void csCommandLineHelper::PrintOption ( const char *  name,
const char *  description,
const csVariant value 
) [static]

Print an option on standard output.

Parameters:
name The name of the option
description A user friendly description of the option
value The default value of the option, at least initialized to the correct type.
static void csCommandLineHelper::PrintOption ( const csOptionDescription option,
const csVariant value 
) [static]

Print an option on standard output.

Parameters:
option The description of the option
value The default value of the option (it can be uninitialized).
static void csCommandLineHelper::PrintTitle ( const char *  title,
unsigned int  level = 0 
) [static]

Print a title on standard output.

Parameters:
title The title
level The level of the title. 0 is the higher level, other levels will be displayed with less emphasis.

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

Generated for Crystal Space 2.0 by doxygen 1.6.1