BloombergLP::balcl::CommandLine

This value-semantic class parses, validates, and provides access to command-line arguments.

Synopsis

Declared in <balcl_commandline.h>

class CommandLine;

Description

The constructor takes the specification describing the command-line arguments. Once created, printUsage can be invoked to print the usage syntax. The parse method takes command-line arguments and validates them against the specification provided at creation, writing a suitable message to an optionally-specified stream in case of a parsing error. Once parsed, options and values can be accessed using various accessors. The class has a set of theType methods (e.g., theString, theInt) that provide access, by name, to the value of the indicated option. It is also possible to link a variable with an option in the specification; doing so will cause the variable to be loaded with the option value once parse has been invoked. The options method returns a balcl::CommandLineOptionsHandle object referring to the option names and their values. A similar but different method, specifiedOptions, is suitable for overwriting other configuration parameters (possibly obtained from a configuration file).

Member Functions

NameDescription
CommandLine [constructor]Constructors
~CommandLine [destructor]Destroy this command-line object.
operator= Assign to this command-line object the value of the specified rhs.
allocator Return the allocator used by this object to supply memory.
hasOption Return true if this command-line object is configured with an option having the specified name, and false otherwise.
hasValue Return true if the option having name has a defined value.
isParsed Return true if this object was parsed successfully, and false otherwise. Note that if parse was invoked but failed, this method returns false.
isSpecified Return true if the option with name was entered on the command line.
isValid Return true if this object is in a valid state, and false otherwise.
numSpecified Return how many times the option with name was entered on the command line.
options Return the command-line options and their values.
parse Parse the command-line arguments in argv of length argc.
position Return the argv index where the option with name was first entered.
positions Return the argv offsets where the option with name was entered.
print Format this command-line object to the specified output stream.
printUsage printUsage overloads
specifiedOptions Return the options that were entered (or set via environment).
theBool Return the value of the option having the specified name.
theChar Return the value of the option having the specified name.
theCharArray Return a const reference to the value of the option having name.
theDate Return a const reference to the value of the option having name.
theDateArray Return a const reference to the value of the option having name.
theDatetime Return a const reference to the value of the option having name.
theDatetimeArray Return a const reference to the value of the option having name.
theDouble Return the value of the option having the specified name.
theDoubleArray Return a const reference to the value of the option having name.
theInt Return the value of the option having the specified name.
theInt64 Return the value of the option having the specified name.
theInt64Array Return a const reference to the value of the option having name.
theIntArray Return a const reference to the value of the option having name.
theString Return a const reference to the value of the option having name.
theStringArray Return a const reference to the value of the option having name.
theTime Return a const reference to the value of the option having name.
theTimeArray Return a const reference to the value of the option having name.
type Return the type of the option having the specified name.
operator BloombergLP::bslmf::NestedTraitDeclaration<CommandLine, HasPrintMethod> Nested trait declaration for bslma::UsesBslmaAllocator.

Static Member Functions

NameDescription
isValidOptionSpecificationTable isValidOptionSpecificationTable overloads

Non-Member Functions

NameDescription
operator!=Return false if the specified lhs and rhs have the same value.
operator==Return true if the specified lhs and rhs have the same value.