STORMM Source Documentation
Loading...
Searching...
No Matches
stormm::testing::CommandLineParser Class Reference

A class for collecting command line information. The class object will function somewhat like a namelist in that it gets loaded with keywords and can return the help messages for its contents upon receiving such a directive, but unlike namelists this one object is designed to be reconfigured for specific programs (even test programs, when it appears nested within the TestEnvironment class). More...

#include <command_line_parser.h>

Public Member Functions

std::string getInputAsString (int width=0) const
 Return the command line text as a string.
 
bool doesProgramExitOnHelp () const
 Obtain a verdict on whether the program is to exit after displaying a help message. This does not affect the setting within the object, but instead reports what the setting is.
 
void activateHelpOnNoArgs ()
 Activate the printout of help messages if no command line arguments are provided.
 
void suppressHelpOnNoArgs ()
 Suppress the printout of help messages if no command line arguments are provided.
 
void activateExitOnHelp ()
 Order the program to exit after displaying general help documentation, with a return value of zero.
 
void preventExitOnHelp ()
 Prevent the program from exiting after displaying general help documentation, with a return value of zero.
 
void parseUserInput (int argc, const char *argv[])
 Supply the internal namelist with command-line input as if parsing from an input file.
 
void coordinateWithPartner (CommandLineParser *other)
 The nature of the command line parser as a unique sort of namelist which can be assembled and recombined from parts also suggests a utility in making multiple CommandLineParser objects in different parts of a program, which might all look at the same command line inputs but take in different information. In order for this to work, each object must be able to know that some other object will handle certain inputs, which should then not trigger warnings or errors.
 
void addControlBlocks (const std::vector< std::string > &list)
 Add a list of relevant namelists that will be displayed in the context of any help message. Arguments to the command line corresponding to each namelist, if recognized, will be passed down to trigger a display of the namelist's own documentation.
 
void addCustomNamelists (const std::vector< NamelistToken > &custom_namelists_in)
 Add a series of custom namelists to the object's repertoire of control blocks, about which it is prepared to dispense user information.
 
 CommandLineParser (const std::string &program_name_in, const std::string &program_description, const std::vector< std::string > &noted_imports_in={}, ExceptionResponse policy_in=ExceptionResponse::WARN)
 The constructor is passed the list of command-line arguments. The object will take the first string in the list as the name of the calling program itself.
 
 CommandLineParser (const std::string &program_name_in, const std::string &program_description, ExceptionResponse policy_in)
 
 CommandLineParser (const CommandLineParser &original)=default
 With no pointers to repair and all members coming from or built using Standard Template Library objects, the default copy and move constructors, as well as copy and move assignment operators, are valid.
 
 CommandLineParser (CommandLineParser &&original)=default
 
CommandLineParseroperator= (const CommandLineParser &original)=default
 
CommandLineParseroperator= (CommandLineParser &&original)=default
 
void addStandardAmberInputs (const std::vector< std::string > &cli_keys)
 Impart the typical comand-line keywords inspired by Amber.
 
void addStandardAmberInputs (const char *key_a, const char *key_b=nullptr, const char *key_c=nullptr, const char *key_d=nullptr)
 
void addStandardAmberInputs ()
 
void addStandardBenchmarkingInputs (const std::vector< std::string > &cli_keys)
 Impart some common benchmarking keywords to the command line interface. Overloading and descriptions of input parameters follow from addStandardAmberInputs(), above.
 
void addStandardBenchmarkingInputs (const char *key_a, const char *key_b=nullptr, const char *key_c=nullptr, const char *key_d=nullptr)
 
void addStandardBenchmarkingInputs ()
 
void addStandardApplicationInputs (const std::vector< std::string > &cli_keys)
 Impart some common application command line arguments to the interface. Overloading and descriptions of input parameters follow from addStandardAmberInputs(), above.
 
void addStandardApplicationInputs (const char *key_a, const char *key_b=nullptr, const char *key_c=nullptr, const char *key_d=nullptr)
 
void addStandardApplicationInputs ()
 
const NamelistEmulatorgetNamelistPointer () const
 Return a pointer to the internal namelist.
 
NamelistEmulatorgetNamelistPointer ()
 

Detailed Description

A class for collecting command line information. The class object will function somewhat like a namelist in that it gets loaded with keywords and can return the help messages for its contents upon receiving such a directive, but unlike namelists this one object is designed to be reconfigured for specific programs (even test programs, when it appears nested within the TestEnvironment class).

Constructor & Destructor Documentation

◆ CommandLineParser() [1/2]

stormm::namelist::CommandLineParser::CommandLineParser ( const std::string & program_name_in,
const std::string & program_description,
const std::vector< std::string > & noted_imports_in = {},
ExceptionResponse policy_in = ExceptionResponse::WARN )

The constructor is passed the list of command-line arguments. The object will take the first string in the list as the name of the calling program itself.

Parameters
program_descriptionA help message tailored for the program as a whole

◆ CommandLineParser() [2/2]

stormm::namelist::CommandLineParser::CommandLineParser ( const CommandLineParser & original)
default

With no pointers to repair and all members coming from or built using Standard Template Library objects, the default copy and move constructors, as well as copy and move assignment operators, are valid.

Parameters
originalTHe original object to copy or move
otherAnother object placed on the right hand side of the assignment statement

Member Function Documentation

◆ addControlBlocks()

void stormm::namelist::CommandLineParser::addControlBlocks ( const std::vector< std::string > & list)

Add a list of relevant namelists that will be displayed in the context of any help message. Arguments to the command line corresponding to each namelist, if recognized, will be passed down to trigger a display of the namelist's own documentation.

Parameters
listThe collection of relevant namelists

◆ addCustomNamelists()

void stormm::namelist::CommandLineParser::addCustomNamelists ( const std::vector< NamelistToken > & custom_namelists_in)

Add a series of custom namelists to the object's repertoire of control blocks, about which it is prepared to dispense user information.

Parameters
custom_namelists_inThe collection of custom namelist classes. These are equivalent to, but not included in, the collection of namelists held in the main libraries. Each CommandLineParser object has an innate ability to search the main libraries' namelists for annotation.

◆ addStandardAmberInputs()

void stormm::namelist::CommandLineParser::addStandardAmberInputs ( const std::vector< std::string > & cli_keys)

Impart the typical comand-line keywords inspired by Amber.

Overloaded:

  • Provide a vector of many Amber input keys
  • Provide a single key or a handful of keys (for developers who forget their { } braces)
  • Load all standard Amber inputs
Parameters
cli_keysThe list of keywords, each of which must match a recognized Amber command line input keyword from one of the major engines
key_aThe first of up to four specific keys
key_bThe second of up to four specific keys
key_cThe third of up to four specific keys
key_dThe fourth of up to four specific keys

◆ coordinateWithPartner()

void stormm::namelist::CommandLineParser::coordinateWithPartner ( CommandLineParser * other)

The nature of the command line parser as a unique sort of namelist which can be assembled and recombined from parts also suggests a utility in making multiple CommandLineParser objects in different parts of a program, which might all look at the same command line inputs but take in different information. In order for this to work, each object must be able to know that some other object will handle certain inputs, which should then not trigger warnings or errors.

Parameters
otherAnother object with which the CommandLineParser should coordinate when parsing command line inputs

◆ getInputAsString()

std::string stormm::namelist::CommandLineParser::getInputAsString ( int width = 0) const

Return the command line text as a string.

Parameters
widthThe width with which to print the command line text, implying a point at which the text wraps

◆ getNamelistPointer()

const NamelistEmulator * stormm::namelist::CommandLineParser::getNamelistPointer ( ) const

Return a pointer to the internal namelist.

Overloaded:

  • Return a const pointer to the namelist emulator for a const object.
  • Return a mutable pointer to the namelist emulator for a non-const object.

◆ parseUserInput()

void stormm::namelist::CommandLineParser::parseUserInput ( int argc,
const char * argv[] )

Supply the internal namelist with command-line input as if parsing from an input file.

Parameters
argcThe number of command-line arguments
argvList of character strings obtained from the command line

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