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

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

Inheritance diagram for senf::console::ProgramOptions:

Public Member Functions

template<class Container >
ProgramOptionsnonOptions (Container &container)
 Set container to add non-option arguments to. More...
 
ProgramOptionsalias (char letter, std::string const &longOpt, bool withArg=false)
 Set short option alias. More...
 
- Public Member Functions inherited from senf::console::detail::BundleMixin
 BundleMixin ()
 
 BundleMixin (DirectoryNode &root)
 
void parse ()
 Parse config file. More...
 
void parse (DirectoryNode &restrict)
 Parse config file under restrict. More...
 
bool complete () const
 true, if all nodes have been parsed More...
 
bool parsed (GenericNode &node) const
 true. if node has been parsed More...
 
void reset ()
 Reset node parse info state. More...
 

Related Functions

(Note that these are not member functions.)

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

Structors and default members

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

Additional Inherited Members

- Protected Member Functions inherited from senf::console::detail::BundleMixin
template<class Source >
Source & add (boost::intrusive_ptr< Source > source)
 

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;
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 58 of file ProgramOptions.hh.

Constructor & Destructor Documentation

◆ ProgramOptions()

senf::console::ProgramOptions::ProgramOptions ( int  argc,
char const **  argv,
DirectoryNode root = senf::console::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.

Member Function Documentation

◆ alias()

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]letteroption letter
[in]longOptlong option alias
[in]withArgtrue, if the option should take an argument.

◆ nonOptions()

template<class Container >
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.

Friends And Related Function Documentation

◆ OptionsConfig()

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

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.

◆ parseOptions()

void parseOptions ( int  argc,
char const **  argv,
DirectoryNode root = senf::console::root() 
)
related

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 file: