MongoDB  2.7.0
Public Member Functions | List of all members
mongo::optionenvironment::OptionSection Class Reference

A container for OptionDescription instances as well as other OptionSection instances. More...

#include <option_section.h>

Public Member Functions

 OptionSection (const std::string &name)
 
Status addSection (const OptionSection &subSection)
 Add a sub section to this section. More...
 
OptionDescriptionaddOptionChaining (const std::string &dottedName, const std::string &singleName, const OptionType type, const std::string &description)
 Add an option to this section, and returns a reference to an OptionDescription to allow for chaining. More...
 
Status getBoostOptions (po::options_description *boostOptions, bool visibleOnly=false, bool includeDefaults=false, OptionSources=SourceAll, bool getEmptySections=true) const
 
Status getBoostPositionalOptions (po::positional_options_description *boostPositionalOptions) const
 
Status getAllOptions (std::vector< OptionDescription > *options) const
 
Status countOptions (int *numOptions, bool visibleOnly, OptionSources sources) const
 
Status getDefaults (std::map< Key, Value > *values) const
 Populates the given map with all the default values for any options in this option section and all sub sections.
 
Status getConstraints (std::vector< boost::shared_ptr< Constraint > > *constraints) const
 Populates the given vector with all the constraints for all options in this section and sub sections.
 
std::string positionalHelpString (const std::string &execName) const
 
std::string helpString () const
 
void dump () const
 

Detailed Description

A container for OptionDescription instances as well as other OptionSection instances.

Provides a description of all options that are supported to be passed in to an OptionsParser. Has utility functions to support the various formats needed by the parsing process

The sections and section names only matter in the help string. For sections in a JSON config, look at the dots in the dottedName of the relevant OptionDescription

Usage:

namespace moe = mongo::optionenvironment;

moe::OptionsParser parser; moe::Environment environment; moe::OptionSection options; moe::OptionSection subSection("Section Name");

// Register our allowed option flags with our OptionSection options.addOptionChaining("help", "help", moe::Switch, "Display Help");

// Register our positional options with our OptionSection options.addOptionChaining("command", "command", moe::String, "Command").positional(1, 1);

// Add a subsection subSection.addOptionChaining("port", "port", moe::Int, "Port"); options.addSection(subSection);

// Run the parser Status ret = parser.run(options, argc, argv, envp, &environment); if (!ret.isOK()) { cerr << options.helpString() << endl; exit(EXIT_FAILURE); }

Member Function Documentation

OptionDescription & mongo::optionenvironment::OptionSection::addOptionChaining ( const std::string &  dottedName,
const std::string &  singleName,
const OptionType  type,
const std::string &  description 
)

Add an option to this section, and returns a reference to an OptionDescription to allow for chaining.

Examples:

options.addOptionChaining("option", "option", moe::String, "Chaining Registration") .hidden().setDefault(moe::Value("default")) .setImplicit(moe::Value("implicit"));

This creates a hidden option that has default and implicit values.

options.addOptionChaining("name", "name", moe::String, "Composing Option") .composing().sources(SourceAllConfig);

This creates an option that is composing and can be specified only in config files.

See the OptionDescription class for details on the supported attributes.

throws DBException on errors, such as attempting to register an option with the same name as another option. These represent programming errors that should not happen during normal operation.

Status mongo::optionenvironment::OptionSection::addSection ( const OptionSection subSection)

Add a sub section to this section.

Used mainly to keep track of section headers for when we need generate the help string for the command line


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