senf::console::ProgramOptions Class Reference
[Accessing the Console/Config tree]

Console node tree based command line option parser. More...

#include <senf/Utils/Console/ProgramOptions.hh>

Inheritance diagram for senf::console::ProgramOptions:
Inheritance graph
[legend]

List of all members.


Detailed Description

Console node tree based command line option parser.

A ProgramOptions instance allows flexible parsing of command line options against the console node tree. If you just want to parse all options, the senf::console::parseOptions() function will do that. ProgramOptions however allows to incrementally parse only a subset of the given command line options.

std::vector<std::string> args;
senf::console::ProgramOptions cf (argc, argv);
cf
    .nonOptions(args)
    .alias('n', "--foo-bar=x")
    .alias('x', "--xxx", true);

// Parse only options under the directory of some object. The object 'ob'
// must have been registered somewhere in the node tree
cf.parse(ob.dir);

// Parse rest of the config file
cf.parse();

If your application uses multiple configuration sources, use a ConfigBundle and OptionsConfig.

Definition at line 67 of file ProgramOptions.hh.


Public Member Functions

template<class Container >
ProgramOptions nonOptions (Container &container)
  Set container to add non-option arguments to.
ProgramOptions alias (char letter, std::string const &longOpt, bool withArg=false)
  Set short option alias.

Related Functions

(Note that these are not member functions.)

void  parseOptions (int argc, char const **argv, DirectoryNode &root=root())
  Parse command line options.
detail::ProgramOptionsSource::ptr  OptionsConfig (int argc, char const **argv)
  ConfigBundle source reading command line options.

Structors and default members

  ProgramOptions (int argc, char const **argv, DirectoryNode &root=root())
  Create ProgramOptions parser for given options.

Constructor & Destructor Documentation

senf::console::ProgramOptions::
ProgramOptions ( int  argc,
char const **  argv,
DirectoryNode root = root() )

Create ProgramOptions parser for given options.

The given argc/argv values are those passed to main by the operating system. Especially argv[0] is not an option and is ignored.

Definition at line 66 of file ProgramOptions.cci.


Member Function Documentation

senf::console::ProgramOptions & senf::console::ProgramOptions::
alias ( char  letter,
std::string const &  longOpt,
bool  withArg = false )

Set short option alias.

A short option is always an alias for a long option with or without argument. if withArg is true, the short option will expect an argument on the command line. This argument will be appended (with an additional '=') to longOpt. If withArg is false (the default), longOpt may optional contain an argument.

Parameters:
[in]  letter  option letter
[in]  longOpt  long option alias
[in]  withArg  true, if the option should take an argument.

Definition at line 72 of file ProgramOptions.cci.

template<class Container >
senf::console::ProgramOptions & senf::console::ProgramOptions::
nonOptions ( Container &  container )

Set container to add non-option arguments to.

container must have a clear() and a push_back(std::string) member. All non-options are added to container. Before parsing the command-line, clear() is called.

Definition at line 74 of file ProgramOptions.cti.


Friends And Related Function Documentation

detail::ProgramOptionsSource::ptr
OptionsConfig ( int  argc,
char const **  argv )

ConfigBundle source reading command line options.

This constructor is used to create a config source parsing the given command line options to add to a ConfigBundle.

void
parseOptions ( int  argc,
char const **  argv,
DirectoryNode root = root() )

Parse command line options.

The command line options in argc / argv will be parsed, interpreting all node's relative to root as root node.


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