[#BloombergLP-balcl-CommandLine]
= xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/balcl.adoc[balcl]::CommandLine
:relfileprefix: ../../
:mrdocs:

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

== Synopsis

Declared in `&lt;balcl&lowbar;commandline&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
class CommandLine;
----

== Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:BloombergLP/balcl/CommandLine/2constructor-03.adoc[`CommandLine`]         [.small]#[constructor]#
| Constructors
| xref:BloombergLP/balcl/CommandLine/2destructor.adoc[`&#126;CommandLine`] [.small]#[destructor]#
| Destroy this command&hyphen;line object&period;
| xref:BloombergLP/balcl/CommandLine/operator_assign.adoc[`operator&equals;`] 
| Assign to this command&hyphen;line object the value of the specified `rhs` command&hyphen;line object and return a reference providing modifiable access to this object&period; The behavior is undefined unless both `rhs` and this object are valid (i&period;e&period;, `isValid()` and `rhs&period;isValid()` both return `true`)&period;
| xref:BloombergLP/balcl/CommandLine/allocator.adoc[`allocator`] 
| Return the allocator used by this object to supply memory&period; Note that if no allocator was supplied at construction the currently installed default allocator at construction is used&period;
| xref:BloombergLP/balcl/CommandLine/hasOption.adoc[`hasOption`] 
| Return `true` if this command&hyphen;line object is configured with an option having the specified `name`, and `false` otherwise&period;
| xref:BloombergLP/balcl/CommandLine/hasValue.adoc[`hasValue`] 
| Return `true` if this command&hyphen;line object&apos;s option having the specified `name` has a defined value, and `false` otherwise&period; An option has a defined value if `isSpecified(name)` or if a default value was configured for the option (see &lcub;Occurrence Information Field&rcub;)&period; The behavior is undefined unless this command&hyphen;line object `isParsed()` and `hasOption(name)`&period;
| xref:BloombergLP/balcl/CommandLine/isParsed.adoc[`isParsed`] 
| Return `true` if this object was parsed successfully, and `false` otherwise&period; Note that if `parse` was invoked but failed, this method returns `false`&period;
| xref:BloombergLP/balcl/CommandLine/isSpecified-02.adoc[`isSpecified`] 
| `isSpecified` overloads
| xref:BloombergLP/balcl/CommandLine/isValid.adoc[`isValid`] 
| Return `true` if this object is in a valid state, and `false` otherwise&period; Objects are in a valid state after construction from a valid set of option specifications (see the function&hyphen;level documentation of the `isValidOptionSpecificationTable` method) and after a successful invocation of the `parse` method&period; Conversely, construction from invalid option specifications or an unsuccessful invocation of the `parse` method leaves this object in an invalid state&period; Note that additional object state is available from the `isParsed` accessor method&period;
| xref:BloombergLP/balcl/CommandLine/numSpecified.adoc[`numSpecified`] 
| Return the number of times the option with the specified `name` has been entered on the command line, or 0 if `name` is not the name of a field in the command&hyphen;line specification passed at construction to this object&period; Note that, in order to receive the valid number of occurrences, the command line must be successfully parsed&period;
| xref:BloombergLP/balcl/CommandLine/options.adoc[`options`] 
| Return the command&hyphen;line options and their values&period; If an option was not entered on the command line _and_ a default value was provided for that option, then that default value will be used (note the difference with the `specifiedOptions` method)&period; If an option was not entered on the command line _and_ no default value was provided for that option, then the corresponding option will be in a null state&period; The behavior is undefined unless `isParsed` returns `true`&period;
| xref:BloombergLP/balcl/CommandLine/parse-05.adoc[`parse`] 
| `parse` overloads
| xref:BloombergLP/balcl/CommandLine/position.adoc[`position`] 
| Return the position where the option with the specified `name` has been entered on the command line (i&period;e&period;, the index in the `argv` argument to the `parse` method)&period; If the option was specified multiple times on the command line, return the position of the first instance&period; If the option was specified as an environment variable but not on the command line, return &hyphen;2&period; If the option was not specified, return &hyphen;1&period; The behavior is undefined unless the option is of scalar type&period;
| xref:BloombergLP/balcl/CommandLine/positions.adoc[`positions`] 
| Return the positions where the option with the specified `name` has been entered on the command line (i&period;e&period;, the offset in the `argv` argument to the `parse` method)&period; If the option was not specified, return an empty vector&period; Note that, in order to receive the valid positions, the command line must be successfully parsed&period;
| xref:BloombergLP/balcl/CommandLine/print.adoc[`print`] 
| Format this command&hyphen;line object to the specified output `stream` at the (absolute value of) the optionally specified indentation `level` and return a reference to `stream`&period; If `level` is specified, optionally specify `spacesPerLevel`, the number of spaces per indentation level for this object&period; If `level` is negative, suppress indentation of the first line&period; The behavior is undefined unless `0 &lt;&equals; spacesPerLevel`&period; If `stream` is not valid on entry, this operation has no effect&period;
| xref:BloombergLP/balcl/CommandLine/printUsage-0b.adoc[`printUsage`] 
| `printUsage` overloads
| xref:BloombergLP/balcl/CommandLine/specifiedOptions.adoc[`specifiedOptions`] 
| Return the command&hyphen;line options and their values&period; If an option was not entered on the command line or set through an environment variable, then the option will be in a null state (note the difference with the `options` method)&period; This method is especially useful for overwriting some other configuration (potentially obtained from a configuration file)&period; The behavior is undefined unless `isParsed` returns `true`&period;
| xref:BloombergLP/balcl/CommandLine/theBool.adoc[`theBool`] 
| Return the value of the option having the specified `name`&period; The value returned matches that returned by `isSpecified(name)`&period; The behavior is undefined unless this command&hyphen;line object `isParsed()`, `hasOption(name)`, and `OptionType&colon;&colon;e&lowbar;BOOL &equals;&equals; type(name)`&period;
| xref:BloombergLP/balcl/CommandLine/theChar.adoc[`theChar`] 
| Return the value of the option having the specified `name`&period; The behavior is undefined unless this command&hyphen;line object `isParsed()`, `hasOption(name)`, `OptionType&colon;&colon;e&lowbar;CHAR &equals;&equals; type(name)`, and `hasValue(name)`&period;
| xref:BloombergLP/balcl/CommandLine/theCharArray.adoc[`theCharArray`] 
| Return a `const` reference to the value of the option having the specified `name`&period; The behavior is undefined unless this command&hyphen;line object `isParsed()`, `hasOption(name)`, `OptionType&colon;&colon;e&lowbar;CHAR&lowbar;ARRAY &equals;&equals; type(name)`, and `hasValue(name)`&period;
| xref:BloombergLP/balcl/CommandLine/theDate.adoc[`theDate`] 
| Return a `const` reference to the value of the option having the specified `name`&period; The behavior is undefined unless this command&hyphen;line object `isParsed()`, `hasOption(name)`, `OptionType&colon;&colon;e&lowbar;DATE &equals;&equals; type(name)`, and `hasValue(name)`&period;
| xref:BloombergLP/balcl/CommandLine/theDateArray.adoc[`theDateArray`] 
| Return a `const` reference to the value of the option having the specified `name`&period; The behavior is undefined unless this command&hyphen;line object `isParsed()`, `hasOption(name)`, `OptionType&colon;&colon;e&lowbar;DATE&lowbar;ARRAY &equals;&equals; type(name)`, and `hasValue(name)`&period;
| xref:BloombergLP/balcl/CommandLine/theDatetime.adoc[`theDatetime`] 
| Return a `const` reference to the value of the option having the specified `name`&period; The behavior is undefined unless this command&hyphen;line object `isParsed()`, `hasOption(name)`, `OptionType&colon;&colon;e&lowbar;DATETIME &equals;&equals; type(name)`, and `hasValue(name)`&period;
| xref:BloombergLP/balcl/CommandLine/theDatetimeArray.adoc[`theDatetimeArray`] 
| Return a `const` reference to the value of the option having the specified `name`&period; The behavior is undefined unless this command&hyphen;line object `isParsed()`, `hasOption(name)`, `OptionType&colon;&colon;e&lowbar;DATETIME&lowbar;ARRAY &equals;&equals; type(name)`, and `hasValue(name)`&period;
| xref:BloombergLP/balcl/CommandLine/theDouble.adoc[`theDouble`] 
| Return the value of the option having the specified `name`&period; The behavior is undefined unless this command&hyphen;line object `isParsed()`, `hasOption(name)`, `OptionType&colon;&colon;e&lowbar;DOUBLE &equals;&equals; type(name)`, and `hasValue(name)`&period;
| xref:BloombergLP/balcl/CommandLine/theDoubleArray.adoc[`theDoubleArray`] 
| Return a `const` reference to the value of the option having the specified `name`&period; The behavior is undefined unless this command&hyphen;line object `isParsed()`, `hasOption(name)`, `OptionType&colon;&colon;e&lowbar;DOUBLE&lowbar;ARRAY &equals;&equals; type(name)`, and `hasValue(name)`&period;
| xref:BloombergLP/balcl/CommandLine/theInt.adoc[`theInt`] 
| Return the value of the option having the specified `name`&period; The behavior is undefined unless this command&hyphen;line object `isParsed()`, `hasOption(name)`, `OptionType&colon;&colon;e&lowbar;INT &equals;&equals; type(name)`, and `hasValue(name)`&period;
| xref:BloombergLP/balcl/CommandLine/theInt64.adoc[`theInt64`] 
| Return the value of the option having the specified `name`&period; The behavior is undefined unless this command&hyphen;line object `isParsed()`, `hasOption(name)`, `OptionType&colon;&colon;e&lowbar;INT64 &equals;&equals; type(name)`, and `hasValue(name)`&period;
| xref:BloombergLP/balcl/CommandLine/theInt64Array.adoc[`theInt64Array`] 
| Return a `const` reference to the value of the option having the specified `name`&period; The behavior is undefined unless this command&hyphen;line object `isParsed()`, `hasOption(name)`, `OptionType&colon;&colon;e&lowbar;INT64&lowbar;ARRAY &equals;&equals; type(name)`, and `hasValue(name)`&period;
| xref:BloombergLP/balcl/CommandLine/theIntArray.adoc[`theIntArray`] 
| Return a `const` reference to the value of the option having the specified `name`&period; The behavior is undefined unless this command&hyphen;line object `isParsed()`, `hasOption(name)`, `OptionType&colon;&colon;e&lowbar;INT&lowbar;ARRAY &equals;&equals; type(name)`, and `hasValue(name)`&period;
| xref:BloombergLP/balcl/CommandLine/theString.adoc[`theString`] 
| Return a `const` reference to the value of the option having the specified `name`&period; The behavior is undefined unless this command&hyphen;line object `isParsed()`, `hasOption(name)`, `OptionType&colon;&colon;e&lowbar;STRING &equals;&equals; type(name)`, and `hasValue(name)`&period;
| xref:BloombergLP/balcl/CommandLine/theStringArray.adoc[`theStringArray`] 
| Return a `const` reference to the value of the option having the specified `name`&period; The behavior is undefined unless this command&hyphen;line object `isParsed()`, `hasOption(name)`, `OptionType&colon;&colon;e&lowbar;STRING&lowbar;ARRAY &equals;&equals; type(name)`, and `hasValue(name)`&period;
| xref:BloombergLP/balcl/CommandLine/theTime.adoc[`theTime`] 
| Return a `const` reference to the value of the option having the specified `name`&period; The behavior is undefined unless this command&hyphen;line object `isParsed()`, `hasOption(name)`, `OptionType&colon;&colon;e&lowbar;TIME &equals;&equals; type(name)`, and `hasValue(name)`&period;
| xref:BloombergLP/balcl/CommandLine/theTimeArray.adoc[`theTimeArray`] 
| Return a `const` reference to the value of the option having the specified `name`&period; The behavior is undefined unless this command&hyphen;line object `isParsed()`, `hasOption(name)`, `OptionType&colon;&colon;e&lowbar;TIME&lowbar;ARRAY &equals;&equals; type(name)`, and `hasValue(name)`&period;
| xref:BloombergLP/balcl/CommandLine/type.adoc[`type`] 
| Return the type of the option having the specified `name`&period; The behavior is undefined unless this command&hyphen;line object `hasOption(name)`&period;
| xref:BloombergLP/balcl/CommandLine/2conversion.adoc[`operator BloombergLP::bslmf::NestedTraitDeclaration&lt;CommandLine, HasPrintMethod&gt;`] 
| Nested trait declaration for `bslma&colon;&colon;UsesBslmaAllocator`&period;
|===


== Static Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:BloombergLP/balcl/CommandLine/isValidOptionSpecificationTable-09.adoc[`isValidOptionSpecificationTable`] 
| `isValidOptionSpecificationTable` overloads
|===


== Non-Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:BloombergLP/balcl/operator_not_eq-05.adoc[`operator!&equals;`]
| Return `false` if the specified `lhs` and `rhs` have the same value, and `true` otherwise&period; Two command&hyphen;line arguments do not have the same value if and only if they have different command&hyphen;line specifications, or one is parsed successfully but the other is not, or neither is, or else both have the same specification and both are parsed successfully but they have different values for at least one flag, option or non&hyphen;option argument&period; Note that two identical copies built with the same option table, but unparsed, are _not_ equal&period;
| xref:BloombergLP/balcl/operator_eq-01.adoc[`operator&equals;&equals;`]
| Return `true` if the specified `lhs` and `rhs` have the same value, and `false` otherwise&period; Two command&hyphen;line arguments have the same value if and only if they are both parsed successfully and have the same command&hyphen;line specifications and the same values for flags, options, and non&hyphen;option arguments&period; Note that two identical copies built with the same option table, but unparsed, are _not_ equal&period;
|===


[.small]#Created with https://www.mrdocs.com[MrDocs]#
